-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
BUG: MaskedArray does not seem to respect ufunc dispatch hierarchy #15200
Comments
963: Add tests and documentation with improvement of downcast type compatibility (part of #845) r=hgrecco a=jthielen As a part of #845, this PR adds tests for downcast type compatibility with Sparse's `COO` and NumPy's `MaskedArray`, along with more careful handling of downcast types throughout the library. Also included is new documentation on array type compatibility, including the type casting hierarchy digraph by @shoyer and @crusaderky. While this PR doesn't fully bring Pint's downcast type compatibility to a completed state, I think this gets it "good enough" for the upcoming release, and the remaining issues are fairly well defined: - MaskedArray non-commutativity (#633 / numpy/numpy#15200) - Dask compatibility (#883) - Addition of CuPy tests (no issue on issue tracker yet) Because of that, I think this can close #845, but if @hgrecco you want that kept open until the above items are resolved, let me know. - [x] Closes #37; Closes #845 - [x] Executed ``black -t py36 . && isort -rc . && flake8`` with no errors - [x] The change is fully covered by automated unit tests - [x] Documented in docs/ as appropriate - [x] Added an entry to the CHANGES file Co-authored-by: Jon Thielen <[email protected]>
ping @mhvk who may have some thoughts here. I suspect the right fix is to define a def add(self, other):
if self._delegate_binop(other):
return NotImplemented
return add(self, other) to def add(self, other):
if self._delegate_binop(other):
return NotImplemented
return np.add(self, other) Currently MaskedArray overrides ufuncs via |
966: Update documentation to address MaskedArray breaking change r=hgrecco a=jthielen As discussed in #963 (comment), #963 introduced a breaking change with MaskedArrays with the implementation of `__array_ufunc__` on Unit. This PR documents this breaking change as prompted by #963 (comment) (with the hope that numpy/numpy#15200 can be resolved soon!) - ~~Closes # (insert issue number)~~ - [x] Executed ``black -t py36 . && isort -rc . && flake8`` with no errors - ~~The change is fully covered by automated unit tests~~ (documentation update only) - [x] Documented in docs/ as appropriate - [x] Added an entry to the CHANGES file Co-authored-by: Jon Thielen <[email protected]>
Yes, |
This test makes sure that a MaskedArray defers properly to another class if it doesn't know how to handle it. See numpy#15200.
This test makes sure that a MaskedArray defers properly to another class if it doesn't know how to handle it. See #15200.
This issue should be re-opened since #16022 was reverted. |
This test makes sure that a MaskedArray defers properly to another class if it doesn't know how to handle it. See numpy#15200.
This test makes sure that a MaskedArray defers properly to another class if it doesn't know how to handle it. See numpy#15200.
This test makes sure that a MaskedArray defers properly to another class if it doesn't know how to handle it. See numpy#15200.
This test makes sure that a MaskedArray defers properly to another class if it doesn't know how to handle it. See numpy#15200.
Reopening, since the PR to use |
When using a custom array container that implements
__array_ufunc__
and is meant to be able to wrap MaskedArrays, non-commutativity occurs in binary operations with MaskedArrays. Despite what the below comment mentions:https://github.com/numpy/numpy/blob/v1.17.3/numpy/ma/core.py#L3960-L3972
it does not properly defer, as seen in the example below. I am unfortunately not well-acquainted with the MaskedArray internals, so I don't know what would be a good way forward for a fix.
xref hgrecco/pint#633
Reproducing code example:
Output:
Numpy/Python version information:
1.17.3 3.6.7 | packaged by conda-forge | (default, Nov 6 2019, 16:19:42)
[GCC 7.3.0]
The text was updated successfully, but these errors were encountered: