Repository navigation
support for units with pint #3594
Copy link
Copy link
Open
Labels
Description
pint's implementation of NEP-18 (see hgrecco/pint#905) is close enough so we can finally start working on the pint support (i.e. make the integration tests pass). This would be the list of tasks to get there:
- integration tests:
- implement integration tests for
DataArray,Datasetand top-level functions (tests for arrays with units #3238, tests for datasets with units #3447, Tests for module-level functions with units #3493) - add tests for
Variableas discussed in Tests for module-level functions with units #3493 (Tests for variables with units #3654) - clean up the current tests (Fix pint integration tests #3600)
- use the standard
assert_identicalandassert_allclosefunctions (Pint support for top-level functions #3611, Pint support for DataArray #3643, Tests for variables with units #3654, Pint support for variables #3706, pint support for Dataset #3975) - clean up the
TestVariable.test_padtests
- implement integration tests for
- actually get xarray to support units:
- top-level functions (Pint support for top-level functions #3611)
-
Variable(Pint support for variables #3706)rolling_windowandidenticalneed larger modifications
-
DataArray(Pint support for DataArray #3643) -
Dataset - silence all the
UnitStrippedWarningsin the testsuite (silence UnitStrippedWarnings #4163) - try to get
nanprodto work with quantities - add support for per variable fill values (allow specifying a fill value per variable #4165)
-
reprwith units (Feature request: show units in dataset overview #2773) - type hierarchy (e.g. for
np.maximum(data_array, quantity)vsnp.maximum(quantity, data_array)) (Consistent Handling of Type Casting Hierarchy #3950)
- update the documentation
- point to pint-xarray (see document the duck array integration status #4530)
- mention the requirement for
UnitRegistry(force_ndarray=True)orUnitRegistry(force_ndarray_like=True)(see https://pint-xarray.readthedocs.io/en/stable/creation.html#attaching-units) - list the known issues (see Pint support for DataArray #3643 (comment) and Pint support for DataArray #3643 (comment)) (document the duck array integration status #4530):
pandas(indexing)bottleneck(bfill,ffill)scipy(interp)numbagg(rolling_exp)numpy.lib.stride_tricks.as_strided:rollingnumpy.vectorize:interpolate_na
-
update the install instructions (we can use standardthis should be done byconda/pipnow)pint-xarray
Reacted by Maximilian Roos, Deepak Cherian, Tom Nicholas, Guido Imperiale, JT Thielen, Aiden Price, Martin Raspaud, Andrew Thomas, John Omotani, Luke Davis and 8 more
Activity
dcherian commentedon Dec 4, 2019
Thanks for leading this effort @keewis.
I would start with the lowest-level operations like the constructors and
align,concat,merge. These are called in many of the other functions so fixing these is a prerequisite for getting the rest working. I've looked at align, concat & merge recently so can help if you need to chat about confusing error messages.What does this mean? You can't have units in a IndexVariable?
keewis commentedon Dec 4, 2019
yes, we had that discussion from #525 (comment) on. Short version:
pd.Indexconverts usingnp.asarrayand support for units probably requires #1603.amcnicho commentedon Mar 11, 2020
Would #3643 be the best place to offer contributions at this point, or somewhere else?
keewis commentedon Mar 11, 2020
I think issues related to
DataArray+pintshould be in #3643, for everything else you can use this issue or new issues / pull requests.If you want to, I'd appreciate someone reviewing the tests in
test_units.pysince I don't think anyone other than me thoroughly looked at all of them. You could also investigate / fix theDatasetissues, investigate the reason for theUnitStrippedWarningsor start writing documentation on how to usepintin combination withxarray.keewis commentedon Jul 2, 2020
so, except from the major issues mentioned above which we won't be able to fix in the near future (but there will probably be workarounds in
pint-xarray) we only have three minor issues:nanprod, support for per variable fill values and the repr (#2773).I don't think
nanprodand the fill values are particularly urgent, so if we get support for therepr(maybe using some sort of hook that a library likepint-xarraycan then use to properly format the duckarray) and put together the documentation page, we could include this in the0.16release.Edit: I guess the release is already big enough so I don't really mind waiting on the next release, but this is really close.
dcherian commentedon Jul 20, 2022
@keewis Shall we close this? It seems the only outstanding one is
nanprodwith quantities. Which sort of indicates that we've made the necessary big changes.keewis commentedon Aug 3, 2022
#6873 might fix the
nanprodissue, and we have a separate issue for the last big change left (#3950, which is not really limited to quantities) so I agree that we should be able to close this with #6873.We might want to open a new issue to get the known issues to work, though.
tennlee commentedon Oct 7, 2025
I just came here from https://xarray.dev/blog/introducing-pint-xarray and wanted to leave a note of thanks for this work. Great job, much appreciated.