-
Notifications
You must be signed in to change notification settings - Fork 13
Calling quantify() on already-quantified data arrays #47
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
Comments
Note I feel pretty unsure about items 3 and 5. Open to discussion on all points. |
I'm sorry for the late reply, @lukelbd, and thanks for the suggestions. I'm not sure about 1: I can sympathize with the desire to have a bare 2 should be pretty uncontroversial, but I think 3 should still raise an error (if you really want to replace a unit, you can always 4 might make sense, although in that case I would drop the attribute: having a unit in both the attribute and the quantity means that the attribute can quickly get out-of-date. In order to allow roundtripping we should probably allow specifying the 5 has the issues of 3 and 4 combined (it replaces the units using possibly out-of-date attributes), so I think this should stay an error. My mental model of Thoughts, @jthielen, @TomNicholas? |
No worries! Just to clarify points 1-5 were all in reference to DataArrays that are quantified. So point 1 means if the underlying data is already Points 2 and 4 are thus no-ops in the same vein as point 1: A non-bare Also agree with you that errors for points 3 and 5 probably make more sense than warnings. Hadn't considered your point about 6 -- definitely makes sense! |
thanks for clarifying, I did misunderstand 1. Yes, if (some of) the data variables / coordinates are already quantified and there are no attributes we could have |
I like the idea of |
Currently, if
data_array.pint.quantify()
is called on an object that is already quantified, aValueError
is always raised:pint-xarray/pint_xarray/accessors.py
Lines 213 to 217 in 93d4fa7
IMHO it would be preferable to have the following behavior changes when calling
quantify
on an already-quantified data arrays, to make things more robust:units
isNone
anddata_array
has no'units'
attribute, do nothing; just return a shallow copy. It makes sense to me ifquantify
behaves like an identify operator on already-quantified arrays. Sort of likenp.array(np.array([1]))
.units
is notNone
, but they match the existingpint.Quantity
units, behave like step 1.units
is notNone
, but they do not match the existing units, replace the units and emit a warning (or raise an error...?).data_array
has a'units'
attribute, but they match the existingpint.Quantity
units, behave like step 1.data_array
has a'units'
attribute, but they do not match the existing units, replace the units and emit a warning (or raise an error...?).Also, the following behavior might be useful whether or not the data is already quantified:
units
is notNone
anddata_array
has a'units'
attribute, ignore the attribute after emitting a warning.Any objections to these changes? If I (...eventually) submit a PR implementing them, would it be accepted?
The text was updated successfully, but these errors were encountered: