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

Can .pint.magnitude return a DataArray instead? #151

Open
dcherian opened this issue Jan 21, 2022 · 8 comments
Open

Can .pint.magnitude return a DataArray instead? #151

dcherian opened this issue Jan 21, 2022 · 8 comments

Comments

@dcherian
Copy link

dcherian commented Jan 21, 2022

Currently DataArray.pint.magnitude returns a numpy array. Can it return a DataArray instead? We can always extract the numpy array using DataArray.data.magnitude.

Just realized I can also use DataArray.as_numpy() but perhaps this is still worth considering?

@TomNicholas
Copy link
Member

I would be okay with this - what say you @keewis?

@keewis
Copy link
Collaborator

keewis commented Jan 31, 2022

this feels pretty similar to .pint.dequantify().drop_attrs("units") (if we had something like .drop_attrs), but it's true that .data.magnitude is much more accessible than that. So I guess defining .pint.magnitude to return a DataArray does make sense?

@TomNicholas
Copy link
Member

If we are going to make this change then we should 100% do it before I release that belated blog post. I would be happy to implement this if we all agree?

@dcherian
Copy link
Author

dcherian commented Feb 1, 2022

👍 The one place as_numpy doesn't work is when it's DataArray(pint(dask(numpy)))

@TomNicholas
Copy link
Member

The one place as_numpy doesn't work is when it's DataArray(pint(dask(numpy)))

"Doesn't work" as in .pint.magnitude returning a DataArray would be the only way to conveniently get back DataArray(dask(numpy))?

@dcherian
Copy link
Author

dcherian commented Feb 1, 2022

^ Yes AFAIK

@keewis
Copy link
Collaborator

keewis commented Feb 1, 2022

I do agree to make the change, but I would argue that .pint.dequantify() should be used to convert between DataArray(pint(dask(numpy))) and DataArray(dask(numpy)) (and if that doesn't work we should fix it). For that, we might want to have the option to save the Unit object instead of the formatted string.

@keewis
Copy link
Collaborator

keewis commented Jun 23, 2024

coming back to this, I think that .pint.dequantify() does what you are looking for, but we might want to allow selectively dequantifying just a subset of the variables instead.

Edit: I'll leave this open until I've come to a conclusion regarding selectively dequantifying variables

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

Successfully merging a pull request may close this issue.

3 participants