Skip to content

Commit 6b17192

Browse files
committed
Fixed IntegerArray division by 0
When dividing by 0, the result should be `inf`, not `NaN`. Closes pandas-dev#27398
1 parent ad0539b commit 6b17192

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

doc/source/whatsnew/v1.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ Other
856856
- Bug in :meth:`DataFrame.append` that raised ``IndexError`` when appending with empty list (:issue:`28769`)
857857
- Fix :class:`AbstractHolidayCalendar` to return correct results for
858858
years after 2030 (now goes up to 2200) (:issue:`27790`)
859+
- Fixed :class:`IntegerArray` returning ``NA`` rather than ``inf`` for operations dividing by 0 (:issue:`27398`)
859860
- Bug in :meth:`Series.count` raises if use_inf_as_na is enabled (:issue:`29478`)
860861

861862

pandas/core/arrays/integer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,10 @@ def _maybe_mask_result(self, result, mask, other, op_name):
700700
op_name : str
701701
"""
702702

703-
# may need to fill infs
704-
# and mask wraparound
705-
if is_float_dtype(result):
706-
mask |= (result == np.inf) | (result == -np.inf)
703+
# # may need to fill infs
704+
# # and mask wraparound
705+
# if is_float_dtype(result):
706+
# mask |= (result == np.inf) | (result == -np.inf)
707707

708708
# if we have a float operand we are by-definition
709709
# a float result
@@ -748,7 +748,7 @@ def integer_arithmetic_method(self, other):
748748

749749
# nans propagate
750750
if mask is None:
751-
mask = self._mask
751+
mask = self._mask.copy()
752752
else:
753753
mask = self._mask | mask
754754

pandas/tests/arrays/test_integer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def _check_divmod_op(self, s, op, other, exc=None):
135135

136136
def _check_op(self, s, op_name, other, exc=None):
137137
op = self.get_op_from_name(op_name)
138+
# breakpoint()
138139
result = op(s, other)
139140

140141
# compute expected

0 commit comments

Comments
 (0)