From e5a6632e1f879726ddf30a53eec8cf2ddb3b04b0 Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 17 Jan 2020 14:33:45 +0100 Subject: [PATCH 01/20] get fillna tests to pass --- xarray/core/duck_array_ops.py | 2 +- xarray/tests/test_units.py | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/xarray/core/duck_array_ops.py b/xarray/core/duck_array_ops.py index 98b371ab7c3..3770ccd0868 100644 --- a/xarray/core/duck_array_ops.py +++ b/xarray/core/duck_array_ops.py @@ -261,7 +261,7 @@ def where_method(data, cond, other=dtypes.NA): def fillna(data, other): - return where(isnull(data), other, data) + return where(notnull(data), data, other) def concatenate(arrays, axis=0): diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index 2cb1550c088..f16815b64c5 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -1545,12 +1545,7 @@ def test_missing_value_detection(self, func): unit_registry.dimensionless, DimensionalityError, id="dimensionless" ), pytest.param(unit_registry.s, DimensionalityError, id="incompatible_unit"), - pytest.param( - unit_registry.cm, - None, - id="compatible_unit", - marks=pytest.mark.xfail(reason="converts to fill value's unit"), - ), + pytest.param(unit_registry.cm, None, id="compatible_unit"), pytest.param(unit_registry.m, None, id="identical_unit"), ), ) From 9414fe36d62c0898669868f203a10f2223dce82a Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 17 Jan 2020 14:38:35 +0100 Subject: [PATCH 02/20] get the _getitem_with_mask tests to pass --- xarray/core/variable.py | 6 +++++- xarray/tests/test_units.py | 9 +-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/xarray/core/variable.py b/xarray/core/variable.py index 0a9d0767b77..31ec0831c35 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -742,7 +742,11 @@ def _getitem_with_mask(self, key, fill_value=dtypes.NA): data = as_indexable(self._data)[actual_indexer] mask = indexing.create_mask(indexer, self.shape, data) - data = duck_array_ops.where(mask, fill_value, data) + if isinstance(mask, bool): + mask = not mask + else: + mask = ~mask + data = duck_array_ops.where(mask, data, fill_value) else: # array cannot be indexed along dimensions of size 0, so just # build the mask directly instead. diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index f16815b64c5..06993c0a873 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -1756,14 +1756,7 @@ def test_1d_math(self, func, unit, error, dtype): unit_registry.dimensionless, DimensionalityError, id="dimensionless" ), pytest.param(unit_registry.s, DimensionalityError, id="incompatible_unit"), - pytest.param( - unit_registry.cm, - None, - id="compatible_unit", - marks=pytest.mark.xfail( - reason="getitem_with_mask converts to the unit of other" - ), - ), + pytest.param(unit_registry.cm, None, id="compatible_unit"), pytest.param(unit_registry.m, None, id="identical_unit"), ), ) From 12d2fe4b98eba684e3496a893edc1ae6571e5919 Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 17 Jan 2020 22:51:16 +0100 Subject: [PATCH 03/20] silence the behavior change warning of pint --- xarray/tests/test_units.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index 06993c0a873..80a75b9e6ba 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -1,4 +1,5 @@ import operator +import warnings import numpy as np import pandas as pd @@ -18,6 +19,13 @@ unit_registry = pint.UnitRegistry(force_ndarray=True) Quantity = unit_registry.Quantity + +# silence pint's BehaviorChangeWarning +with warnings.catch_warnings(): + warnings.simplefilter("ignore") + Quantity([]) + + pytestmark = [ pytest.mark.skipif( not IS_NEP18_ACTIVE, reason="NUMPY_EXPERIMENTAL_ARRAY_FUNCTION is not enabled" From 077d67abcf976c4ba6089813104bb09051c8ef31 Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 17 Jan 2020 22:53:01 +0100 Subject: [PATCH 04/20] don't use 0 as fill value since that has special behaviour --- xarray/tests/test_units.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index 80a75b9e6ba..c0dfd1f51ff 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -1543,12 +1543,7 @@ def test_missing_value_detection(self, func): @pytest.mark.parametrize( "unit,error", ( - pytest.param( - 1, - DimensionalityError, - id="no_unit", - marks=pytest.mark.xfail(reason="uses 0 as a replacement"), - ), + pytest.param(1, DimensionalityError, id="no_unit"), pytest.param( unit_registry.dimensionless, DimensionalityError, id="dimensionless" ), @@ -1558,7 +1553,7 @@ def test_missing_value_detection(self, func): ), ) def test_missing_value_fillna(self, unit, error): - value = 0 + value = 10 array = ( np.array( [ From e03fac86e081435c79f6c9f3cf18c75557a8bef1 Mon Sep 17 00:00:00 2001 From: Keewis Date: Sun, 19 Jan 2020 19:33:09 +0100 Subject: [PATCH 05/20] use concat as a class method --- xarray/tests/test_units.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index c0dfd1f51ff..90cef388604 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -1944,16 +1944,19 @@ def test_concat(self, unit, error, dtype): if error is not None: with pytest.raises(error): - variable.concat(other) + xr.Variable.concat([variable, other], dim="y") return units = extract_units(variable) expected = attach_units( - strip_units(variable).concat(strip_units(convert_units(other, units))), + xr.Variable.concat( + [strip_units(variable), strip_units(convert_units(other, units))], + dim="y", + ), units, ) - actual = variable.concat(other) + actual = xr.Variable.concat([variable, other], dim="y") assert_units_equal(expected, actual) xr.testing.assert_identical(expected, actual) From 6b65a76aea21d3287bc054bd2755fc65daeae85a Mon Sep 17 00:00:00 2001 From: Keewis Date: Sun, 19 Jan 2020 23:34:43 +0100 Subject: [PATCH 06/20] use np.pad after trimming instead of concatenating a filled array --- xarray/core/variable.py | 28 ++++++++++------------------ xarray/tests/test_units.py | 7 +------ 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/xarray/core/variable.py b/xarray/core/variable.py index 31ec0831c35..5a7ceed52bf 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -1103,24 +1103,16 @@ def _shift_one_dim(self, dim, count, fill_value=dtypes.NA): else: dtype = self.dtype - shape = list(self.shape) - shape[axis] = min(abs(count), shape[axis]) - - if isinstance(trimmed_data, dask_array_type): - chunks = list(trimmed_data.chunks) - chunks[axis] = (shape[axis],) - full = functools.partial(da.full, chunks=chunks) - else: - full = np.full - - filler = full(shape, fill_value, dtype=dtype) - - if count > 0: - arrays = [filler, trimmed_data] - else: - arrays = [trimmed_data, filler] - - data = duck_array_ops.concatenate(arrays, axis) + width = min(abs(count), self.shape[axis]) + dim_pad = (width, 0) if count >= 0 else (0, width) + pads = [(0, 0) if d != dim else dim_pad for d in self.dims] + + data = np.pad( + trimmed_data.astype(dtype), + pads, + mode="constant", + constant_values=fill_value, + ) if isinstance(data, dask_array_type): # chunked data should come out with the same chunks; this makes diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index 90cef388604..35cde972f2b 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -1840,12 +1840,7 @@ def test_squeeze(self, dtype): ), method("reduce", np.std, "x"), method("round", 2), - pytest.param( - method("shift", {"x": -2}), - marks=pytest.mark.xfail( - reason="trying to concatenate ndarray to quantity" - ), - ), + method("shift", {"x": -2}), method("transpose", "y", "x"), ), ids=repr, From 88320ef488072a66afb3d175889e8838d00e4718 Mon Sep 17 00:00:00 2001 From: Keewis Date: Sun, 19 Jan 2020 23:41:05 +0100 Subject: [PATCH 07/20] rewrite the concat test to pass appropriate arrays --- xarray/tests/test_units.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index 35cde972f2b..f8d56b342f1 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -1915,7 +1915,6 @@ def test_unstack(self, dtype): assert_units_equal(expected, actual) xr.testing.assert_identical(expected, actual) - @pytest.mark.xfail(reason="ignores units") @pytest.mark.parametrize( "unit,error", ( @@ -1930,12 +1929,12 @@ def test_unstack(self, dtype): ) def test_concat(self, unit, error, dtype): array1 = ( - np.linspace(0, 5, 3 * 10).reshape(3, 10).astype(dtype) * unit_registry.m + np.linspace(0, 5, 9 * 10).reshape(3, 6, 5).astype(dtype) * unit_registry.m ) - array2 = np.linspace(5, 10, 10 * 2).reshape(10, 2).astype(dtype) * unit + array2 = np.linspace(5, 10, 10 * 3).reshape(3, 2, 5).astype(dtype) * unit - variable = xr.Variable(("x", "y"), array1) - other = xr.Variable(("y", "z"), array2) + variable = xr.Variable(("x", "y", "z"), array1) + other = xr.Variable(("x", "y", "z"), array2) if error is not None: with pytest.raises(error): From 1e07dce4b8fd59057d22ae3d7884a1114c78e22a Mon Sep 17 00:00:00 2001 From: Keewis Date: Mon, 20 Jan 2020 02:38:45 +0100 Subject: [PATCH 08/20] use da.pad when dealing with dask arrays --- xarray/core/variable.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xarray/core/variable.py b/xarray/core/variable.py index 5a7ceed52bf..314f7096fe0 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -1107,7 +1107,12 @@ def _shift_one_dim(self, dim, count, fill_value=dtypes.NA): dim_pad = (width, 0) if count >= 0 else (0, width) pads = [(0, 0) if d != dim else dim_pad for d in self.dims] - data = np.pad( + if isinstance(trimmed_data, dask_array_type): + pad_func = da.pad + else: + pad_func = np.pad + + data = pad_func( trimmed_data.astype(dtype), pads, mode="constant", From ce572de9012261c259a09db46035704a0fbf8725 Mon Sep 17 00:00:00 2001 From: Keewis Date: Wed, 22 Jan 2020 20:12:42 +0100 Subject: [PATCH 09/20] mark the failing pad tests as xfail when on a current pint version --- xarray/tests/test_units.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index abbe20a6355..12e574f9219 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -1,3 +1,4 @@ +from distutils.version import LooseVersion import operator import warnings @@ -2029,7 +2030,8 @@ def test_no_conflicts(self, unit, dtype): DimensionalityError, id="no_unit", marks=pytest.mark.xfail( - reason="is not treated the same as dimensionless" + LooseVersion(pint.__version__) < LooseVersion("0.10.2"), + reason="bug in pint's implementation of np.pad", ), ), pytest.param( From 3d16f2e6c40c9b984f207b9b54c127a25ee4a4ca Mon Sep 17 00:00:00 2001 From: Keewis Date: Wed, 5 Feb 2020 15:58:05 +0100 Subject: [PATCH 10/20] update whats-new.rst --- doc/whats-new.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 7fa70d0b67a..f0c7f99c02d 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -24,6 +24,8 @@ Breaking changes New Features ~~~~~~~~~~~~ +- implement pint support. (:issue:`3594`, :pull:`3706`) + By `Justus Magin `_. Bug fixes ~~~~~~~~~ From a8cf968f6d009f8e1e22867c5b0d266feacc6946 Mon Sep 17 00:00:00 2001 From: Keewis Date: Wed, 5 Feb 2020 16:08:00 +0100 Subject: [PATCH 11/20] fix the import order --- 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 ca9b87ad978..bf605a08d46 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -1,6 +1,6 @@ -from distutils.version import LooseVersion import operator import warnings +from distutils.version import LooseVersion import numpy as np import pandas as pd From 98e2b40654ee9cabe7c4c43443088b4c0aad31ba Mon Sep 17 00:00:00 2001 From: Keewis Date: Wed, 5 Feb 2020 17:32:56 +0100 Subject: [PATCH 12/20] test using pint master --- ci/azure/install.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/azure/install.yml b/ci/azure/install.yml index e11a8b54db3..9ae6dcdb102 100644 --- a/ci/azure/install.yml +++ b/ci/azure/install.yml @@ -29,6 +29,7 @@ steps: git+https://github.com/zarr-developers/zarr \ git+https://github.com/Unidata/cftime \ git+https://github.com/mapbox/rasterio \ + git+https://github.com/hgrecco/pint git+https://github.com/pydata/bottleneck condition: eq(variables['UPSTREAM_DEV'], 'true') displayName: Install upstream dev dependencies From 05946b1ef25683a38a594df4138780ad46c073bb Mon Sep 17 00:00:00 2001 From: Keewis Date: Wed, 5 Feb 2020 17:43:36 +0100 Subject: [PATCH 13/20] fix the install command --- ci/azure/install.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/azure/install.yml b/ci/azure/install.yml index 9ae6dcdb102..958e3c180fa 100644 --- a/ci/azure/install.yml +++ b/ci/azure/install.yml @@ -29,7 +29,7 @@ steps: git+https://github.com/zarr-developers/zarr \ git+https://github.com/Unidata/cftime \ git+https://github.com/mapbox/rasterio \ - git+https://github.com/hgrecco/pint + git+https://github.com/hgrecco/pint \ git+https://github.com/pydata/bottleneck condition: eq(variables['UPSTREAM_DEV'], 'true') displayName: Install upstream dev dependencies From 8c490ee0edb1133d6fe7571bce5c3e5c68e4d9b0 Mon Sep 17 00:00:00 2001 From: Keewis Date: Wed, 5 Feb 2020 18:45:27 +0100 Subject: [PATCH 14/20] reimplement the pad test to really work with units --- xarray/tests/test_units.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index bf605a08d46..a19e253a849 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -2025,6 +2025,43 @@ def test_no_conflicts(self, unit, dtype): assert expected == actual + def test_pad(self, dtype): + data = np.arange(4 * 3 * 2).reshape(4, 3, 2).astype(dtype) * unit_registry.m + v = xr.Variable(["x", "y", "z"], data) + + xr_args = [{"x": (2, 1)}, {"y": (0, 3)}, {"x": (3, 1), "z": (2, 0)}] + np_args = [ + ((2, 1), (0, 0), (0, 0)), + ((0, 0), (0, 3), (0, 0)), + ((3, 1), (0, 0), (2, 0)), + ] + for xr_arg, np_arg in zip(xr_args, np_args): + actual = v.pad_with_fill_value(**xr_arg) + expected = xr.Variable( + v.dims, + np.pad( + v.data.astype(float), + np_arg, + mode="constant", + constant_values=np.nan, + ), + ) + xr.testing.assert_identical(expected, actual) + assert_units_equal(expected, actual) + assert isinstance(actual._data, type(v._data)) + + # for the boolean array, we pad False + data = np.full_like(data, False, dtype=bool).reshape(4, 3, 2) + v = xr.Variable(["x", "y", "z"], data) + for xr_arg, np_arg in zip(xr_args, np_args): + actual = v.pad_with_fill_value(fill_value=data.flat[0], **xr_arg) + expected = xr.Variable( + v.dims, + np.pad(v.data, np_arg, mode="constant", constant_values=v.data.flat[0]), + ) + xr.testing.assert_identical(actual, expected) + assert_units_equal(expected, actual) + @pytest.mark.parametrize( "unit,error", ( From f6eca88ba43a3c71e4f16e3e7f260a42abbc78f1 Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 7 Feb 2020 12:27:13 +0100 Subject: [PATCH 15/20] use np.logical_not instead --- xarray/core/variable.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/xarray/core/variable.py b/xarray/core/variable.py index 912d53f811c..17e88d1c84a 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -742,11 +742,7 @@ def _getitem_with_mask(self, key, fill_value=dtypes.NA): data = as_indexable(self._data)[actual_indexer] mask = indexing.create_mask(indexer, self.shape, data) - if isinstance(mask, bool): - mask = not mask - else: - mask = ~mask - data = duck_array_ops.where(mask, data, fill_value) + data = duck_array_ops.where(np.logical_not(mask), data, fill_value) else: # array cannot be indexed along dimensions of size 0, so just # build the mask directly instead. From 72241e50daabb9d39d2870d546833ee0f93b1fd2 Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 7 Feb 2020 12:32:32 +0100 Subject: [PATCH 16/20] use duck_array_ops to provide pad --- xarray/core/duck_array_ops.py | 1 + xarray/core/variable.py | 7 +------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/xarray/core/duck_array_ops.py b/xarray/core/duck_array_ops.py index 991c5985b2b..e0ed0f7db95 100644 --- a/xarray/core/duck_array_ops.py +++ b/xarray/core/duck_array_ops.py @@ -121,6 +121,7 @@ def notnull(data): isin = _dask_or_eager_func("isin", array_args=slice(2)) take = _dask_or_eager_func("take") broadcast_to = _dask_or_eager_func("broadcast_to") +pad = _dask_or_eager_func("pad") _concatenate = _dask_or_eager_func("concatenate", list_of_args=True) _stack = _dask_or_eager_func("stack", list_of_args=True) diff --git a/xarray/core/variable.py b/xarray/core/variable.py index 17e88d1c84a..6d1429df235 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -1103,12 +1103,7 @@ def _shift_one_dim(self, dim, count, fill_value=dtypes.NA): dim_pad = (width, 0) if count >= 0 else (0, width) pads = [(0, 0) if d != dim else dim_pad for d in self.dims] - if isinstance(trimmed_data, dask_array_type): - pad_func = da.pad - else: - pad_func = np.pad - - data = pad_func( + data = duck_array_ops.pad( trimmed_data.astype(dtype), pads, mode="constant", From 2ebfa6b5a29185fed0c58451072521b5f0c6f33f Mon Sep 17 00:00:00 2001 From: Keewis Date: Fri, 7 Feb 2020 18:35:02 +0100 Subject: [PATCH 17/20] add comments explaining the order of the arguments to where --- xarray/core/duck_array_ops.py | 2 ++ xarray/core/variable.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/xarray/core/duck_array_ops.py b/xarray/core/duck_array_ops.py index e0ed0f7db95..5d16de09c3d 100644 --- a/xarray/core/duck_array_ops.py +++ b/xarray/core/duck_array_ops.py @@ -262,6 +262,8 @@ def where_method(data, cond, other=dtypes.NA): def fillna(data, other): + # we need to pass data first so pint has a chance of returning the + # correct unit return where(notnull(data), data, other) diff --git a/xarray/core/variable.py b/xarray/core/variable.py index 6d1429df235..ecd44f25207 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -742,6 +742,8 @@ def _getitem_with_mask(self, key, fill_value=dtypes.NA): data = as_indexable(self._data)[actual_indexer] mask = indexing.create_mask(indexer, self.shape, data) + # we need to invert the mask in order to pass data first. This helps + # pint to choose the correct unit data = duck_array_ops.where(np.logical_not(mask), data, fill_value) else: # array cannot be indexed along dimensions of size 0, so just From 0a0c2d3c55d136ad79e84ec09155018ba201bdf5 Mon Sep 17 00:00:00 2001 From: Keewis Date: Sun, 23 Feb 2020 16:26:14 +0100 Subject: [PATCH 18/20] mark the flipped parameter changes with a todo --- xarray/core/duck_array_ops.py | 1 + xarray/core/variable.py | 1 + 2 files changed, 2 insertions(+) diff --git a/xarray/core/duck_array_ops.py b/xarray/core/duck_array_ops.py index 5d16de09c3d..06e12e83abd 100644 --- a/xarray/core/duck_array_ops.py +++ b/xarray/core/duck_array_ops.py @@ -264,6 +264,7 @@ def where_method(data, cond, other=dtypes.NA): def fillna(data, other): # we need to pass data first so pint has a chance of returning the # correct unit + # TODO: revert after https://github.com/hgrecco/pint/issues/1019 is fixed return where(notnull(data), data, other) diff --git a/xarray/core/variable.py b/xarray/core/variable.py index ecd44f25207..058b7bf52d4 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -744,6 +744,7 @@ def _getitem_with_mask(self, key, fill_value=dtypes.NA): mask = indexing.create_mask(indexer, self.shape, data) # we need to invert the mask in order to pass data first. This helps # pint to choose the correct unit + # TODO: revert after https://github.com/hgrecco/pint/issues/1019 is fixed data = duck_array_ops.where(np.logical_not(mask), data, fill_value) else: # array cannot be indexed along dimensions of size 0, so just From 4cadc52f78e609160e761e0cf711845eb6bcf235 Mon Sep 17 00:00:00 2001 From: Keewis Date: Sun, 23 Feb 2020 16:30:11 +0100 Subject: [PATCH 19/20] skip the identical tests --- xarray/tests/test_units.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index a19e253a849..737872c9c00 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -1594,13 +1594,7 @@ def test_missing_value_fillna(self, unit, error): pytest.param(1, id="no_unit"), pytest.param(unit_registry.dimensionless, id="dimensionless"), pytest.param(unit_registry.s, id="incompatible_unit"), - pytest.param( - unit_registry.cm, - id="compatible_unit", - marks=pytest.mark.xfail( - reason="checking for identical units does not work properly, yet" - ), - ), + pytest.param(unit_registry.cm, id="compatible_unit",), pytest.param(unit_registry.m, id="identical_unit"), ), ) @@ -1611,7 +1605,17 @@ def test_missing_value_fillna(self, unit, error): pytest.param(True, id="with_conversion"), ), ) - @pytest.mark.parametrize("func", (method("equals"), method("identical")), ids=repr) + @pytest.mark.parametrize( + "func", + ( + method("equals"), + pytest.param( + method("identical"), + marks=pytest.mark.skip(reason="behaviour of identical is unclear"), + ), + ), + ids=repr, + ) def test_comparisons(self, func, unit, convert_data, dtype): array = np.linspace(0, 1, 9).astype(dtype) quantity1 = array * unit_registry.m From b51caa42d05566d1fe41d8bd155a9f2195b9e96a Mon Sep 17 00:00:00 2001 From: Keewis Date: Sun, 23 Feb 2020 16:31:05 +0100 Subject: [PATCH 20/20] remove the warnings filter --- xarray/tests/test_units.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index 737872c9c00..75e743c3455 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -1,5 +1,4 @@ import operator -import warnings from distutils.version import LooseVersion import numpy as np @@ -22,12 +21,6 @@ Quantity = unit_registry.Quantity -# silence pint's BehaviorChangeWarning -with warnings.catch_warnings(): - warnings.simplefilter("ignore") - Quantity([]) - - pytestmark = [ pytest.mark.skipif( not IS_NEP18_ACTIVE, reason="NUMPY_EXPERIMENTAL_ARRAY_FUNCTION is not enabled"