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
Show file tree
Hide file tree
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
Next Next commit
CI: update tests for numpy 1.20 change to floordiv
  • Loading branch information
jbrockmendel committed Nov 30, 2020
commit cb85bb8d0bd08c6d299fc28cd48db27a89a746ec
6 changes: 5 additions & 1 deletion pandas/tests/arrays/integer/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import numpy as np
import pytest

from pandas.compat.numpy import _np_version_under1p20

import pandas as pd
import pandas._testing as tm
from pandas.core.arrays import integer_array
Expand Down Expand Up @@ -197,7 +199,9 @@ def test_arith_coerce_scalar(data, all_arithmetic_operators):
result = op(s, other)
expected = op(s.astype(float), other)
# rfloordiv results in nan instead of inf
if all_arithmetic_operators == "__rfloordiv__":
if all_arithmetic_operators == "__rfloordiv__" and _np_version_under1p20:
# for numpy 1.20 https://github.com/numpy/numpy/pull/16161
# updated floordiv, now matches our behavior defined in core.ops
expected[(expected == np.inf) | (expected == -np.inf)] = np.nan

tm.assert_series_equal(result, expected)
Expand Down
11 changes: 8 additions & 3 deletions pandas/tests/arrays/sparse/test_arithmetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import numpy as np
import pytest

from pandas.compat.numpy import _np_version_under1p20

import pandas as pd
import pandas._testing as tm
from pandas.core import ops
Expand Down Expand Up @@ -44,9 +46,12 @@ 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)
mask = np.isinf(expected)
if mask.any():
expected[mask] = np.nan
if _np_version_under1p20:
# numpy 1.20 updated floordiv, matching the behavior
# in core.ops. See https://github.com/numpy/numpy/pull/16161
mask = np.isinf(expected)
if mask.any():
expected[mask] = np.nan

self._assert(result, expected)

Expand Down
0