Skip to content

BUG: MaskedNDArray.__array_ufunc__ breaks for erfa.atioq #16123

Closed

Description

@neutrinoceros

Related to (but independent of) #16116. Also discovered while working on #16070

import erfa
import astropy.units as u

from astropy.coordinates.builtin_frames.altaz import AltAz
from astropy.coordinates.erfa_astrom import erfa_astrom
from astropy.coordinates import EarthLocation
from astropy.utils.masked import Masked

obeserved_frame = AltAz(
    obstime="2024-02-28 10:33:24.505563",
    location=EarthLocation(6378137.0, 0.0, 0.0),
    pressure=0.0 << u.hPa,
    temperature=0.0 << u.deg_C,
    relative_humidity=0.0,
    obswl=1.0 << u.micron,
)

astrom = erfa_astrom.get().apco(obeserved_frame)
inputs = (0, 1, astrom)

r1 = erfa.atioq(*inputs) # this works
r2 = erfa.atioq(*(Masked(_) for _ in inputs)) # this doesn't
Traceback (most recent call last):
  File "/Users/clm/dev/astropy-project/coordinated/astropy/bugs/16116/g.py", line 25, in <module>
    r2 = erfa.atioq(*(Masked(_) for _ in inputs))
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/clm/.pyenv/versions/astropy.dev/lib/python3.12/site-packages/erfa/core.py", line 4058, in atioq
    aob, zob, hob, dob, rob = ufunc.atioq(ri, di, astrom)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/clm/dev/astropy-project/coordinated/astropy/astropy/utils/masked/core.py", line 807, in __array_ufunc__
    mask = self._combine_masks(masks, out=out_mask, where=where_unmasked)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/clm/dev/astropy-project/coordinated/astropy/astropy/utils/masked/core.py", line 704, in _combine_masks
    np.logical_or(out, mask, out=out, where=where)
TypeError: Cannot cast array data from dtype([('pmt', '?'), ('eb', '?', (3,)), ('eh', '?', (3,)), ('em', '?'), ('v', '?', (3,)), ('bm1', '?'), ('bpn', '?', (3, 3)), ('along', '?'), ('phi', '?'), ('xpl', '?'), ('ypl', '?'), ('sphi', '?'), ('cphi', '?'), ('diurab', '?'), ('eral', '?'), ('refa', '?'), ('refb', '?')]) to dtype('bool').

Activity

  1. changed the title [-]BUG: `Masked.__array_ufunc__` breaks for `era.atioq`[/-] [+]BUG: `MaskedNDArray.__array_ufunc__` breaks for `era.atioq`[/+] on Feb 28, 2024
  2. neutrinoceros commented on Feb 28, 2024

    @neutrinoceros
    ContributorAuthor

    For what it's worth, I checked that #16121 doesn't fix this.

  3. mhvk commented on Feb 28, 2024

    @mhvk
    Contributor

    Yes, this is a different problem, that __array_ufunc__ doesn't work with structured arrays (or, rather, that _combine_masks doesn't). I think it shouldn't be too hard to fix...

  4. neutrinoceros commented on Feb 28, 2024

    @neutrinoceros
    ContributorAuthor

    I'm happy to have a go at it if needed, but I don't want to step on your toes. Just let me know !

  5. mhvk commented on Feb 28, 2024

    @mhvk
    Contributor

    I'm happy to have a go at it if needed, but I don't want to step on your toes. Just let me know !

    PR is forthcoming...

  6. mhvk commented on Feb 28, 2024

    @mhvk
    Contributor

    Fix in #16125 - though built on top of #16120, so best to merge in order & rebase.

  7. changed the title [-]BUG: `MaskedNDArray.__array_ufunc__` breaks for `era.atioq`[/-] [+]BUG: `MaskedNDArray.__array_ufunc__` breaks for `erfa.atioq`[/+] on Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions