Skip to content
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

Implement NA.__array_ufunc__ #30245

Merged
merged 29 commits into from
Jan 5, 2020
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bf8680f
Implement NA.__array_ufunc__
TomAugspurger Dec 12, 2019
0c69bd0
Merge remote-tracking branch 'upstream/master' into na-array-ufunc
TomAugspurger Dec 13, 2019
46f2327
ndarrays
TomAugspurger Dec 13, 2019
075d58a
move
TomAugspurger Dec 16, 2019
b72dd1c
Merge remote-tracking branch 'upstream/master' into na-array-ufunc
TomAugspurger Dec 16, 2019
0371cf4
setup, prints
TomAugspurger Dec 16, 2019
878ef70
docs
TomAugspurger Dec 16, 2019
97af2e9
fixup
TomAugspurger Dec 16, 2019
f175a34
fixups
TomAugspurger Dec 16, 2019
f2ac945
Merge remote-tracking branch 'upstream/master' into na-array-ufunc
TomAugspurger Dec 17, 2019
0f4e121
lint
TomAugspurger Dec 17, 2019
fe04554
Merge remote-tracking branch 'upstream/master' into na-array-ufunc
TomAugspurger Dec 18, 2019
cf9ac10
Merge remote-tracking branch 'upstream/master' into na-array-ufunc
TomAugspurger Dec 20, 2019
72e2b67
Fixups
TomAugspurger Dec 20, 2019
8d90e9d
Merge branch 'master' of https://github.com/pandas-dev/pandas into na…
TomAugspurger Dec 28, 2019
6a2fc68
Merge remote-tracking branch 'upstream/master' into na-array-ufunc
TomAugspurger Dec 30, 2019
db4cc40
Merge remote-tracking branch 'upstream/master' into na-array-ufunc
TomAugspurger Dec 30, 2019
7b1585a
fix bug
TomAugspurger Dec 30, 2019
b79e07f
update
TomAugspurger Dec 30, 2019
567c584
test special
TomAugspurger Dec 30, 2019
b27470d
doc
TomAugspurger Dec 30, 2019
c7c9184
move
TomAugspurger Dec 30, 2019
a0dbca8
Merge remote-tracking branch 'upstream/master' into na-array-ufunc
TomAugspurger Jan 2, 2020
ce209f9
fixup
TomAugspurger Jan 2, 2020
e4ecadb
fixup
TomAugspurger Jan 2, 2020
8d2763d
Merge remote-tracking branch 'upstream/master' into na-array-ufunc
TomAugspurger Jan 4, 2020
f68e178
restore
TomAugspurger Jan 4, 2020
d8c23e9
fixup
TomAugspurger Jan 4, 2020
4c30bb4
Merge remote-tracking branch 'upstream/master' into na-array-ufunc
TomAugspurger Jan 5, 2020
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
Prev Previous commit
Next Next commit
fixup
TomAugspurger committed Dec 16, 2019
commit 97af2e9186027d3be9dc0f4a9d326c87f9c1628e
9 changes: 6 additions & 3 deletions pandas/_libs/missing.pyx
Original file line number Diff line number Diff line change
@@ -465,9 +465,12 @@ class NAType(C_NAType):
result = maybe_dispatch_ufunc_to_dunder_op(self, ufunc, method, *inputs, **kwargs)
if result is NotImplemented:
# TODO: this is wrong for binary, ternary ufuncs. Should handle shape stuff.
TomAugspurger marked this conversation as resolved.
Show resolved Hide resolved
if ufunc.nout == 1:
result = NA
else:
index, = [i for i, x in enumerate(inputs) if x is NA]
result = np.broadcast_arrays(*inputs)[index]
if result.ndim == 0:
result = result.item()
if ufunc.nout > 1:
result = (result,) * ufunc.nout
result = (NA,) * ufunc.nout
TomAugspurger marked this conversation as resolved.
Show resolved Hide resolved

return result
10 changes: 10 additions & 0 deletions pandas/tests/scalar/test_na_scalar.py
Original file line number Diff line number Diff line change
@@ -206,3 +206,13 @@ def test_ufunc():
def test_ufunc_raises():
with pytest.raises(ValueError, match="ufunc method 'at'"):
np.log.at(pd.NA, 0)


def test_binary_input_not_dunder():
a = np.array([1, 2, 3])
expected = np.array([pd.NA, pd.NA, pd.NA], dtype=object)
result = np.logaddexp(a, pd.NA)
tm.assert_numpy_array_equal(result, expected)

result = np.logaddexp(pd.NA, a)
tm.assert_numpy_array_equal(result, expected)