8000 CI: update tests for numpy 1.20 change to floordiv by jbrockmendel · Pull Request #38172 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

CI: update tests for numpy 1.20 change to floordiv #38172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 30, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.

Loading

Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
jbrockmendel committed Nov 30, 2020
commit dec6413f9bd97ab802c9f058abf41119ecaf8fbb
21 changes: 18 additions & 3 deletions pandas/tests/arrays/sparse/test_arithmetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pandas as pd
import pandas._testing as tm
from pandas.core import ops
from pandas.core.arrays.sparse import SparseArray, SparseDtype
from pandas.core.arrays.sparse import IntIndex, SparseArray, SparseDtype


@pytest.fixture(params=["integer", "block"])
Expand All @@ -31,7 +31,7 @@ class TestSparseArrayArithmetics:
def _assert(self, a, b):
tm.assert_numpy_array_equal(a, b)

def _check_numeric_ops(self, a, b, a_dense, b_dense, mix, op):
def _check_numeric_ops(self, a, b, a_dense, b_dense, mix, op, flag=False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is flag for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover from previous attempt at a fix, will remove

with np.errstate(invalid="ignore", divide="ignore"):
if mix:
result = op(a, b_dense).to_dense()
Expand All @@ -46,7 +46,22 @@ def _check_numeric_ops(self, a, b, a_dense, b_dense, mix, op):

if op in [operator.floordiv, ops.rfloordiv]:
# Series sets 1//0 to np.inf, which SparseArray does not do (yet)
if _np_version_under1p20:
condition = _np_version_under1p20
if isinstance(a_dense, np.ndarray) and isinstance(b_dense, np.ndarray):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add some comments here on what is changed, it is non-obvious from inspection what is changing (e.g. what is true in prior version and what is true now)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yah as mentioned above, i have no frikkin idea what the underlying logic is here

condition = True
if a_dense.dtype == np.float64 and np.isnan(a.fill_value):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems really fragile

# NB: these conditions are just guess-and-check
# to find what passes, no idea why these particular
# conditions are necessary.
if b_dense.dtype == np.int64 and mix:
condition = False

if a.sp_index.equals(b.sp_index):
if not mix:
condition = False
elif isinstance(a.sp_index, IntIndex):
condition = False
if condition:
# numpy 1.20 updated floordiv, matching the behavior
# in core.ops. See https://github.com/numpy/numpy/pull/16161
mask = np.isinf(expected)
Expand Down
0