pint-xarray
pint-xarray copied to clipboard
Can .pint.magnitude return a DataArray instead?
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?
I would be okay with this - what say you @keewis?
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?
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?
:+1: The one place as_numpy
doesn't work is when it's DataArray(pint(dask(numpy)))
The one place
as_numpy
doesn't work is when it'sDataArray(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))
?
^ Yes AFAIK
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.
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