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

Preserve ndarray-like magnitudes or reject them from the start #479

Closed
gerritholl opened this issue Feb 22, 2017 · 2 comments · Fixed by #959
Closed

Preserve ndarray-like magnitudes or reject them from the start #479

gerritholl opened this issue Feb 22, 2017 · 2 comments · Fixed by #959
Labels
numpy Numpy related bug/enhancement

Comments

@gerritholl
Copy link
Contributor

I am trying to use a xarray.DataArray magnitude with a pint quantity. It appears to work, but doesn't really, because Quantity.__getattr__ forces it to convert to numpy.ndarray. This leads to conversion at very unexpected behaviour:

    In [526]: q = ureg.Quantity(xarray.DataArray([1, 2, 3]), 'm')
    
    In [527]: print(q)
    <xarray.DataArray (dim_0: 3)>array([1, 2, 3])Dimensions without coordinates: dim_0 meter
    
    In [528]: a = array(q)
    
    In [529]: print(q)
    [1 2 3] meter

I think pint should either accept magnitudes that behave like numpy.ndarray but don't subclass it (such as xarray.DataArray), or reject them when the object is constructed. I don't see how converting it in the middle of attribute lookup can do any good…

@hgrecco
Copy link
Owner

hgrecco commented Dec 3, 2019

Revisit after #905

@hgrecco hgrecco added the numpy Numpy related bug/enhancement label Dec 3, 2019
@jthielen
Copy link
Contributor

jthielen commented Dec 4, 2019

I believe this should be resolved by #845, which is the more general issue about array-like compatibility, so I think this can be closed?

(For the example at hand, this should not be allowed, as xarray DataArrays should wrap pint Quantities and not the other way around.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
numpy Numpy related bug/enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants