-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Fix IntegerArray pow for special cases #30210
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
Changes from 6 commits
81b18ca
5374d8b
f0264f9
9e5a69c
b5a4112
8cb89e1
a96e6d6
62ba6a0
b8eefcf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -718,13 +718,13 @@ def _create_arithmetic_method(cls, op): | |
@unpack_zerodim_and_defer(op.__name__) | ||
def integer_arithmetic_method(self, other): | ||
|
||
mask = None | ||
omask = None | ||
|
||
if getattr(other, "ndim", 0) > 1: | ||
raise NotImplementedError("can only perform ops with 1-d structures") | ||
|
||
if isinstance(other, IntegerArray): | ||
other, mask = other._data, other._mask | ||
other, omask = other._data, other._mask | ||
|
||
elif is_list_like(other): | ||
other = np.asarray(other) | ||
|
@@ -742,17 +742,28 @@ def integer_arithmetic_method(self, other): | |
raise TypeError("can only perform ops with numeric values") | ||
|
||
# nans propagate | ||
if mask is None: | ||
if omask is None: | ||
mask = self._mask.copy() | ||
else: | ||
mask = self._mask | mask | ||
mask = self._mask | omask | ||
|
||
# 1 ** np.nan is 1. So we have to unmask those. | ||
if op_name == "pow": | ||
mask = np.where(self == 1, False, mask) | ||
# 1 ** x is 1. | ||
mask = np.where((self._data == 1) & ~self._mask, False, mask) | ||
# x ** 0 is 1. | ||
if omask is not None: | ||
mask = np.where((other == 0) & ~omask, False, mask) | ||
else: | ||
mask = np.where(other == 0, False, mask) | ||
|
||
elif op_name == "rpow": | ||
mask = np.where(other == 1, False, mask) | ||
# 1 ** x is 1. | ||
if omask is not None: | ||
mask = np.where((other == 1) & ~omask, False, mask) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, no, because it is for the reversed op? (maybe add a comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your call on whether a comment is needed. It's clear IMO, though I wrote it :) |
||
else: | ||
mask = np.where(other == 1, False, mask) | ||
# x ** 0 is 1. | ||
mask = np.where((self._data == 0) & ~self._mask, False, mask) | ||
|
||
with np.errstate(all="ignore"): | ||
result = op(self._data, other) | ||
|
Uh oh!
There was an error while loading. Please reload this page.