8000 tests for arrays with units (#3238) · pydata/xarray@55b1ac0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 55b1ac0

Browse files
keewismax-sixty
authored andcommitted
tests for arrays with units (#3238)
* create the empty test file * add tests for data array aggregation functions * include pint in the ci * ignore missing type annotations for pint * really skip the tests if pint is not available * remove the reason from the importorskip call * test that the dataarray constructor does not strip the unit * convert every unit stripped warning to an error * work around pint not implementing np.allclose yet * remove the now unnecessary filterwarnings decorator * xfail all tests that depend on pint having a __array_function__ * treat nans as equal * implement tests for simple arithmetic operations * use param's id argument to assign readable names * add tests for sel() and isel() * add more readable names for the unary arithmetics * xfail every test that is not yet xfailing These don't pass because the constructor raises a unit stripped warning - fixed in pint#764. * only xfail if pint is not the current development version This is test is not really reliable, but sufficient for now. * always use lists instead of tuples for indexing * add tests for loc and squeeze * black * add names and xfail marks to the parameters * add tests for interp and interp_like * implement tests for reindex * remove the xfail marks where it is not clear yet that pint is to blame * add tests for reindex_like * don't pass the new DataArray to a kwarg * xfail if not on pint dev * refactor the tests * add tests for univariate and bivariate ufuncs * black * xfail aggregation only if pint does not implement __array_function__ yet * remove the global filterwarnings mark apparently, this caused the tests to change behavior, resulting in different errors, or causing tests to pass that should actually fail. * add a test case for the repr * create a pytest mark that explicitly requires pint's __array_function__ * also check the string representation in addition to the repr * add helpers for creating method tests * check that simple aggregation methods work * use format() instead of format strings * make sure the repr of method calls is different from functions * merge the two aggregation tests * explicitly check whether pint supports __array_function__ relying on versions is somewhat fragile. * provide a fallback for the new base quantity * check that no warning is raised for both with and without coords * also check that the repr works both with and without coords * wrap all aggregation function calls * xfail every call that fails because of something outside xarray * xfail tests related to dimension coordinates and indexes * use the dimensions from the original array * allow passing arguments to the method on call * add tests for comparisons * add tests for detecting, filling and dropping missing values * mark the missing value tests as requiring pint to support duck arrays * add tests for isin, where and interpolate_na * reformat unit ids and add a test parameter for compatible units * remove an unnecessary xfail * add tests for the top-level replication functions (*_like) * check for whatever pint does with *_like functions * add tests for combine_first * xfail the bivariate ufunc tests * xfail the call to np.median * move the top-level function tests out of the DataArray namespace class * add cumsum and cumprod to the list of aggregation functions * add tests for the numpy methods * check for equal units directly after checking the magnitude * add tests for content manipulation methods * add tests for comparing DataArrays (equals, indentical) * add a test for broadcast_equals * refactor the comparison operation tests * rewrite the strip, attach and assert_equal functions and add extract * preserve multiindex in strip and attach * attach the unit from element "data" as fallback * fix some small typos * compare QuantityScalar and QuantitySequence based on their values * make the isel test more robust * add tests for reshaping and reordering * unify the structure of the tests * mark the remaining tests as requiring a recent pint version, too * explicitly handle quantities as parameters * change the repr of the function / method wrappers * check whether __init__ and repr / str handle units in data and coords * generalize array_attach_units * move the redefinition of DimensionalityError * identify quantities using isinstance * typo * skip tests with a pint version without __array_function__ * compare DataArrays where possible * mark only the compatible unit as xfailing * preserve the name of data arrays * also attach units to x_mm * Test in more CI environments; documentation * What's New * remove a stale function * use Quantity directly for instance tests * explicitly set roll_coords to silence a deprecation warning * skip the whole module if pint does not implement __array_function__ the advantage is that now forgetting to decorate a test case is not possible. * allow to attach units using the mapping from extract_units * add tests for computation methods resampling fails until I figure out how to use it with non-datetime coords. * add tests for grouped operations * add a test for rolling_exp * add a todo note for the module level skip on __array_function__ * add a test for dot * use attach_units instead of manually attaching * modify the resample test to actually work * add a test for to_unstacked_dataset * update whats-new.rst and installing.rst * reformat the whats-new.rst entry * What's New
1 parent 1f81338 commit 55b1ac0

File tree

9 files changed

+1667
-2
lines changed

9 files changed

+1667
-2
lines changed

ci/requirements/py36-min-all-deps.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies:
3131
- numba=0.44
3232
- numpy=1.14
3333
- pandas=0.24
34+
# - pint # See py36-min-nep18.yml
3435
- pip
3536
- pseudonetcdf=3.0
3637
- pydap=3.2

ci/requirements/py36-min-nep18.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ name: xarray-tests
22
channels:
33
- conda-forge
44
dependencies:
5-
# Optional dependencies that require NEP18, such as sparse,
5+
# Optional dependencies that require NEP18, such as sparse and pint,
66
# require drastically newer packages than everything else
77
- python=3.6
88
- coveralls
99
- dask=2.4
1010
- distributed=2.4
1111
- numpy=1.17
1212
- pandas=0.24
13+
- pint=0.9 # Actually not enough as it doesn't implement __array_function__yet!
1314
- pytest
1415
- pytest-cov
1516
- pytest-env

ci/requirements/py36.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies:
2727
- numba
2828
- numpy
2929
- pandas
30+
- pint
3031
- pip
3132
- pseudonetcdf
3233
- pydap

ci/requirements/py37-windows.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies:
2727
- numba
2828
- numpy
2929
- pandas
30+
- pint
3031
- pip
3132
- pseudonetcdf
3233
- pydap

ci/requirements/py37.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies:
2727
- numba
2828
- numpy
2929
- pandas
30+
- pint
3031
- pip
3132
- pseudonetcdf
3233
- pydap

doc/installing.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ For plotting
6666
Alternative data containers
6767
~~~~~~~~~~~~~~~~~~~~~~~~~~~
6868
- `sparse <https://sparse.pydata.org/>`_: for sparse arrays
69+
- `pint <https://pint.readthedocs.io/>`_: for units of measure
70+
71+
.. note::
72+
73+
At the moment of writing, xarray requires a `highly experimental version of pint
74+
<https://github.com/andrewgsavage/pint/pull/6>`_ (install with
75+
``pip install git+https://github.com/andrewgsavage/pint.git@refs/pull/6/head)``.
76+
Even with it, interaction with non-numpy array libraries, e.g. dask or sparse, is broken.
77+
6978
- Any numpy-like objects that support
7079
`NEP-18 <https://numpy.org/neps/nep-0018-array-function-protocol.html>`_.
7180
Note that while such libraries theoretically should work, they are untested.
@@ -85,7 +94,7 @@ dependencies:
8594
(`NEP-29 <https://numpy.org/neps/nep-0029-deprecation_policy.html>`_)
8695
- **pandas:** 12 months
8796
- **scipy:** 12 months
88-
- **sparse** and other libraries that rely on
97+
- **sparse, pint** and other libraries that rely on
8998
`NEP-18 <https://numpy.org/neps/nep-0018-array-function-protocol.html>`_
9099
for integration: very latest available versions only, until the technology will have
91100
matured. This extends to dask when used in conjunction with any of these libraries.

doc/whats-new.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ What's New
1818
v0.14.1 (unreleased)
1919
--------------------
2020

21+
New Features
22+
~~~~~~~~~~~~
23+
- Added integration tests against `pint <https://pint.readthedocs.io/>`_.
24+
(:pull:`3238`) by `Justus Magin <https://github.com/keewis>`_.
25+
26+
.. note::
27+
28+
At the moment of writing, these tests *as well as the ability to use pint in general*
29+
require `a highly experimental version of pint
30+
<https://github.com/andrewgsavage/pint/pull/6>`_ (install with
31+
``pip install git+https://github.com/andrewgsavage/pint.git@refs/pull/6/head)``.
32+
Even with it, interaction with non-numpy array libraries, e.g. dask or sparse, is broken.
33+
2134
Documentation
2235
~~~~~~~~~~~~~
2336

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ ignore_missing_imports = True
7373
ignore_missing_imports = True
7474
[mypy-pandas.*]
7575
ignore_missing_imports = True
76+
[mypy-pint.*]
77+
ignore_missing_imports = True
7678
[mypy-PseudoNetCDF.*]
7779
ignore_missing_imports = True
7880
[mypy-pydap.*]

0 commit comments

Comments
 (0)
0