diff --git a/pandas/tests/arrays/integer/test_arithmetic.py b/pandas/tests/arrays/integer/test_arithmetic.py index cf382dd5e37e0..ae5538a2a85a2 100644 --- a/pandas/tests/arrays/integer/test_arithmetic.py +++ b/pandas/tests/arrays/integer/test_arithmetic.py @@ -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 @@ -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) diff --git a/pandas/tests/arrays/sparse/test_arithmetics.py b/pandas/tests/arrays/sparse/test_arithmetics.py index c9f1dd7f589fc..61f4e3e50d09d 100644 --- a/pandas/tests/arrays/sparse/test_arithmetics.py +++ b/pandas/tests/arrays/sparse/test_arithmetics.py @@ -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 @@ -116,9 +118,15 @@ def _check_logical_ops(self, a, b, a_dense, b_dense): @pytest.mark.parametrize("scalar", [0, 1, 3]) @pytest.mark.parametrize("fill_value", [None, 0, 2]) def test_float_scalar( - self, kind, mix, all_arithmetic_functions, fill_value, scalar + self, kind, mix, all_arithmetic_functions, fill_value, scalar, request ): op = all_arithmetic_functions + + if not _np_version_under1p20: + if op in [operator.floordiv, ops.rfloordiv]: + mark = pytest.mark.xfail(strict=False, reason="GH#38172") + request.node.add_marker(mark) + values = self._base([np.nan, 1, 2, 0, np.nan, 0, 1, 2, 1, np.nan]) a = self._klass(values, kind=kind, fill_value=fill_value) @@ -142,15 +150,11 @@ def test_float_scalar_comparison(self, kind): self._check_comparison_ops(a, 0, values, 0) self._check_comparison_ops(a, 3, values, 3) - def test_float_same_index(self, kind, mix, all_arithmetic_functions): + def test_float_same_index_without_nans( + self, kind, mix, all_arithmetic_functions, request + ): # when sp_index are the same op = all_arithmetic_functions - values = self._base([np.nan, 1, 2, 0, np.nan, 0, 1, 2, 1, np.nan]) - rvalues = self._base([np.nan, 2, 3, 4, np.nan, 0, 1, 3, 2, np.nan]) - - a = self._klass(values, kind=kind) - b = self._klass(rvalues, kind=kind) - self._check_numeric_ops(a, b, values, rvalues, mix, op) values = self._base([0.0, 1.0, 2.0, 6.0, 0.0, 0.0, 1.0, 2.0, 1.0, 0.0]) rvalues = self._base([0.0, 2.0, 3.0, 4.0, 0.0, 0.0, 1.0, 3.0, 2.0, 0.0]) @@ -159,6 +163,24 @@ def test_float_same_index(self, kind, mix, all_arithmetic_functions): b = self._klass(rvalues, kind=kind, fill_value=0) self._check_numeric_ops(a, b, values, rvalues, mix, op) + def test_float_same_index_with_nans( + self, kind, mix, all_arithmetic_functions, request + ): + # when sp_index are the same + op = all_arithmetic_functions + + if not _np_version_under1p20: + if op in [operator.floordiv, ops.rfloordiv]: + mark = pytest.mark.xfail(strict=False, reason="GH#38172") + request.node.add_marker(mark) + + values = self._base([np.nan, 1, 2, 0, np.nan, 0, 1, 2, 1, np.nan]) + rvalues = self._base([np.nan, 2, 3, 4, np.nan, 0, 1, 3, 2, np.nan]) + + a = self._klass(values, kind=kind) + b = self._klass(rvalues, kind=kind) + self._check_numeric_ops(a, b, values, rvalues, mix, op) + def test_float_same_index_comparison(self, kind): # when sp_index are the same values = self._base([np.nan, 1, 2, 0, np.nan, 0, 1, 2, 1, np.nan]) @@ -324,9 +346,14 @@ def test_bool_array_logical(self, kind, fill_value): b = self._klass(rvalues, kind=kind, dtype=np.bool_, fill_value=fill_value) self._check_logical_ops(a, b, values, rvalues) - def test_mixed_array_float_int(self, kind, mix, all_arithmetic_functions): + def test_mixed_array_float_int(self, kind, mix, all_arithmetic_functions, request): op = all_arithmetic_functions + if not _np_version_under1p20: + if op in [operator.floordiv, ops.rfloordiv] and mix: + mark = pytest.mark.xfail(strict=True, reason="GH#38172") + request.node.add_marker(mark) + rdtype = "int64" values = self._base([np.nan, 1, 2, 0, np.nan, 0, 1, 2, 1, np.nan])