Skip to content

Commit

Permalink
adapt the pint + dask test to the newest version of pint (#7855)
Browse files Browse the repository at this point in the history
* use the registry to create the quantities

* skip the `pint` + `dask` test before `pint=0.21`

* also parse the static version
  • Loading branch information
keewis authored May 25, 2023
1 parent 69445c6 commit fd0ac3e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions xarray/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -5627,16 +5627,20 @@ def test_merge(self, variant, unit, error, dtype):

@requires_dask
class TestPintWrappingDask:
@pytest.mark.skipif(
version.parse(pint.__version__) <= version.parse("0.21"),
reason="pint didn't support dask properly before 0.21",
)
def test_duck_array_ops(self):
import dask.array

d = dask.array.array([1, 2, 3])
q = pint.Quantity(d, units="m")
q = unit_registry.Quantity(d, units="m")
da = xr.DataArray(q, dims="x")

actual = da.mean().compute()
actual.name = None
expected = xr.DataArray(pint.Quantity(np.array(2.0), units="m"))
expected = xr.DataArray(unit_registry.Quantity(np.array(2.0), units="m"))

assert_units_equal(expected, actual)
# Don't use isinstance b/c we don't want to allow subclasses through
Expand Down

0 comments on commit fd0ac3e

Please sign in to comment.