Skip to content

Commit

Permalink
adapt the pint + dask test to the newest version of pint (pydat…
Browse files Browse the repository at this point in the history
…a#7855)

* 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 and dstansby committed Jun 28, 2023
1 parent 44eadcf commit 1327d4b
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 @@ -5766,16 +5766,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 1327d4b

Please sign in to comment.