Skip to content

Commit bd6eb7e

Browse files
authored
TST: fix Nullable xfails (#44685)
1 parent db10480 commit bd6eb7e

File tree

7 files changed

+28
-30
lines changed

7 files changed

+28
-30
lines changed

doc/source/whatsnew/v1.4.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ Numeric
629629
- Bug in :class:`DataFrame` arithmetic ops with a subclass whose :meth:`_constructor` attribute is a callable other than the subclass itself (:issue:`43201`)
630630
- Bug in arithmetic operations involving :class:`RangeIndex` where the result would have the incorrect ``name`` (:issue:`43962`)
631631
- Bug in arithmetic operations involving :class:`Series` where the result could have the incorrect ``name`` when the operands having matching NA or matching tuple names (:issue:`44459`)
632+
- Bug in division with ``IntegerDtype`` or ``BooleanDtype`` array and NA scalar incorrectly raising (:issue:`44685`)
632633
-
633634

634635
Conversion

pandas/core/arrays/boolean.py

+2
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ def _arith_method(self, other, op):
508508
# actual op, so we need to choose the resulting dtype manually
509509
if op_name in {"floordiv", "rfloordiv", "mod", "rmod", "pow", "rpow"}:
510510
dtype = "int8"
511+
elif op_name in {"truediv", "rtruediv"}:
512+
dtype = "float64"
511513
else:
512514
dtype = "bool"
513515
result = np.zeros(len(self._data), dtype=dtype)

pandas/core/arrays/numeric.py

+5
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ def _arith_method(self, other, op):
136136

137137
if other is libmissing.NA:
138138
result = np.ones_like(self._data)
139+
if "truediv" in op_name and self.dtype.kind != "f":
140+
# The actual data here doesn't matter since the mask
141+
# will be all-True, but since this is division, we want
142+
# to end up with floating dtype.
143+
result = result.astype(np.float64)
139144
else:
140145
with np.errstate(all="ignore"):
141146
result = op(self._data, other)

pandas/tests/arrays/masked/test_arithmetic.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ def test_array_scalar_like_equivalence(data, all_arithmetic_operators):
4949

5050

5151
def test_array_NA(data, all_arithmetic_operators, request):
52-
if "truediv" in all_arithmetic_operators and data[0].dtype.kind != "f":
53-
mark = pytest.mark.xfail(reason="division with pd.NA fails")
54-
request.node.add_marker(mark)
55-
5652
data, _ = data
5753
op = tm.get_op_from_name(all_arithmetic_operators)
5854
check_skip(data, all_arithmetic_operators)
@@ -169,14 +165,22 @@ def test_error_len_mismatch(data, all_arithmetic_operators):
169165
def test_unary_op_does_not_propagate_mask(data, op, request):
170166
# https://github.com/pandas-dev/pandas/issues/39943
171167
data, _ = data
172-
if data.dtype in ["Float32", "Float64"] and op == "__invert__":
173-
request.node.add_marker(
174-
pytest.mark.xfail(
175-
raises=TypeError, reason="invert is not implemented for float ea dtypes"
176-
)
177-
)
178-
s = pd.Series(data)
179-
result = getattr(s, op)()
168+
ser = pd.Series(data)
169+
170+
if op == "__invert__" and data.dtype.kind == "f":
171+
# we follow numpy in raising
172+
msg = "ufunc 'invert' not supported for the input types"
173+
with pytest.raises(TypeError, match=msg):
174+
getattr(ser, op)()
175+
with pytest.raises(TypeError, match=msg):
176+
getattr(data, op)()
177+
with pytest.raises(TypeError, match=msg):
178+
# Check that this is still the numpy behavior
179+
getattr(data._data, op)()
180+
181+
return
182+
183+
result = getattr(ser, op)()
180184
expected = result.copy(deep=True)
181-
s[0] = None
185+
ser[0] = None
182186
tm.assert_series_equal(result, expected)

pandas/tests/extension/test_boolean.py

-9
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,6 @@ def check_opname(self, s, op_name, other, exc=None):
150150
# overwriting to indicate ops don't raise an error
151151
super().check_opname(s, op_name, other, exc=None)
152152

153-
@pytest.mark.skip(reason="Tested in tests/arrays/test_boolean.py")
154-
def test_compare_scalar(self, data, comparison_op):
155-
pass
156-
157-
@pytest.mark.skip(reason="Tested in tests/arrays/test_boolean.py")
158-
def test_compare_array(self, data, comparison_op):
159-
pass
160-
161153

162154
class TestReshaping(base.BaseReshapingTests):
163155
pass
@@ -378,7 +370,6 @@ def check_reduce(self, s, op_name, skipna):
378370
tm.assert_almost_equal(result, expected)
379371

380372

381-
@pytest.mark.skip(reason="Tested in tests/reductions/test_reductions.py")
382373
class TestBooleanReduce(base.BaseBooleanReduceTests):
383374
pass
384375

pandas/tests/extension/test_floating.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ def data_for_grouping(dtype):
8989

9090

9191
class TestDtype(base.BaseDtypeTests):
92-
@pytest.mark.skip(reason="using multiple dtypes")
93-
def test_is_dtype_unboxes_dtype(self):
94-
# we have multiple dtypes, so skip
95-
pass
92+
pass
9693

9794

9895
class TestArithmeticOps(base.BaseArithmeticOpsTests):

pandas/tests/extension/test_integer.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,7 @@ def data_for_grouping(dtype):
101101

102102

103103
class TestDtype(base.BaseDtypeTests):
104-
@pytest.mark.skip(reason="using multiple dtypes")
105-
def test_is_dtype_unboxes_dtype(self):
106-
# we have multiple dtypes, so skip
107-
pass
104+
pass
108105

109106

110107
class TestArithmeticOps(base.BaseArithmeticOpsTests):
@@ -196,6 +193,7 @@ class TestMissing(base.BaseMissingTests):
196193

197194
class TestMethods(base.BaseMethodsTests):
198195
@pytest.mark.skip(reason="uses nullable integer")
196+
@pytest.mark.parametrize("dropna", [True, False])
199197
def test_value_counts(self, all_data, dropna):
200198
all_data = all_data[:10]
201199
if dropna:

0 commit comments

Comments
 (0)