From 5266fe3015886459150a993536e04f2bfa34b31f Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Fri, 21 Apr 2023 19:58:24 +0200 Subject: [PATCH 1/3] use the registry to create the quantities --- xarray/tests/test_units.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index 9e872c93c0c..d612f648fdb 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -5631,12 +5631,12 @@ 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 From c4671c229383fe0e4847c3398c17f50565231244 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Sat, 20 May 2023 13:29:48 +0200 Subject: [PATCH 2/3] skip the `pint` + `dask` test before `pint=0.21` --- xarray/tests/test_units.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index d612f648fdb..822e4c214ac 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -5627,6 +5627,10 @@ def test_merge(self, variant, unit, error, dtype): @requires_dask class TestPintWrappingDask: + @pytest.mark.skipif( + version.parse(pint.__version__) <= "0.21", + reason="pint didn't support dask properly before 0.21", + ) def test_duck_array_ops(self): import dask.array From 58458a218b25d3218b09fc55095dc6986197351a Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Sat, 20 May 2023 13:43:46 +0200 Subject: [PATCH 3/3] also parse the static version --- xarray/tests/test_units.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index 822e4c214ac..ad9da0fad33 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -5628,7 +5628,7 @@ def test_merge(self, variant, unit, error, dtype): @requires_dask class TestPintWrappingDask: @pytest.mark.skipif( - version.parse(pint.__version__) <= "0.21", + version.parse(pint.__version__) <= version.parse("0.21"), reason="pint didn't support dask properly before 0.21", ) def test_duck_array_ops(self):