Closed
Description
Currently, if data_array.pint.quantify()
is called on an object that is already quantified, a ValueError
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:
- If
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]))
. - If
units
is notNone
, but they match the existingpint.Quantity
units, behave like step 1. - If
units
is notNone
, but they do not match the existing units, replace the units and emit a warning (or raise an error...?). - If
data_array
has a'units'
attribute, but they match the existingpint.Quantity
units, behave like step 1. - If
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:
- If both
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?
Metadata
Metadata
Assignees
Labels
No labels