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

TST: np.fix check fails with numpy-dev (TypeError: cannot write to unmasked output) #14571

Closed
pllim opened this issue Mar 23, 2023 · 7 comments · Fixed by #14590
Closed

TST: np.fix check fails with numpy-dev (TypeError: cannot write to unmasked output) #14571

pllim opened this issue Mar 23, 2023 · 7 comments · Fixed by #14590

Comments

@pllim
Copy link
Member

pllim commented Mar 23, 2023

Started popping up in numpy-dev jobs. @mhvk is investigating.

____________________________ TestUfuncLike.test_fix ____________________________

self = <astropy.utils.masked.tests.test_function_helpers.TestUfuncLike object at 0x7fdd354916c0>

    def test_fix(self):
>       self.check(np.fix)

astropy/utils/masked/tests/test_function_helpers.py:672: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
astropy/utils/masked/tests/test_function_helpers.py:75: in check
    o = func(self.ma, *args, **kwargs)
astropy/utils/masked/core.py:842: in __array_function__
    return super().__array_function__(function, types, args, kwargs)
numpy/lib/ufunclike.py:62: in fix
    res = nx.floor(x, out=res, where=nx.greater_equal(x, 0))
astropy/utils/masked/core.py:828: in __array_ufunc__
    result = getattr(ufunc, method)(*unmasked, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = MaskedNDArray([[  ———,  True,  True],
               [ True,   ———,  True]])
ufunc = <ufunc 'floor'>, method = '__call__'
inputs = (array([[0., 1., 2.],
       [3., 4., 5.]]),)
kwargs = {'where': MaskedNDArray([[  ———,  True,  True],
               [ True,   ———,  True]])}
out = (array([[0., 1., 2.],
       [3., 4., 5.]]),)
out_unmasked = (array([[0., 1., 2.],
       [3., 4., 5.]]),), out_mask = None
out_masks = (None,), d = array([[0., 1., 2.],
       [3., 4., 5.]]), m = None

    def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
        out = kwargs.pop("out", None)
        out_unmasked = None
        out_mask = None
        if out is not None:
            out_unmasked, out_masks = self._get_data_and_masks(*out)
            for d, m in zip(out_unmasked, out_masks):
                if m is None:
                    # TODO: allow writing to unmasked output if nothing is masked?
                    if d is not None:
>                       raise TypeError("cannot write to unmasked output")
E                       TypeError: cannot write to unmasked output

astropy/utils/masked/core.py:701: TypeError
@mhvk
Copy link
Contributor

mhvk commented Mar 23, 2023

Ah, yes, that was numpy/numpy#23240 and we actually checked in that discussion whether it would pose problems for astropy - numpy/numpy#23240 (comment) - conclusion was that only np.fix was affected and that it would be a trivial fix. I'll make that now...

@pllim
Copy link
Member Author

pllim commented Mar 27, 2023

@mhvk , any update on this? 🙏

@byrdie
Copy link
Contributor

byrdie commented Mar 27, 2023

@mhvk, if you haven't started on this yet I could attempt to fix this since I'm the one who messed it up.

@mhvk
Copy link
Contributor

mhvk commented Mar 27, 2023

I got a simple fix that will work for all versions, and a more complicated one, which allows Masked to deal with masked where generally that would be good for the next version (since it is an API change). Let me just push up the simple one; I can always revert that for the more complete version.

@mhvk
Copy link
Contributor

mhvk commented Mar 27, 2023

See #14589

@mhvk
Copy link
Contributor

mhvk commented Mar 28, 2023

See updated and better fix for 5.3 in #14590, with a simpler fix for 5.2.2 and 5.0.6 in #14591.

@mhvk
Copy link
Contributor

mhvk commented Mar 28, 2023

@byrdie - review of #14590 would be most appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants