Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
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
47 changes: 37 additions & 10 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 All @@ -29,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 Down Expand Up @@ -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)
Expand All @@ -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])
Expand All @@ -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])
Expand Down Expand Up @@ -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])
Expand Down