From 128f3ab3c413a030feb0cf2d38cc8370defd3a48 Mon Sep 17 00:00:00 2001 From: RondeauG Date: Wed, 16 Aug 2023 15:14:32 -0400 Subject: [PATCH 1/4] fix raise_flags --- tests/test_flags.py | 3 +++ xclim/core/dataflags.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_flags.py b/tests/test_flags.py index 6240f2ef1..9bd8b925e 100644 --- a/tests/test_flags.py +++ b/tests/test_flags.py @@ -125,6 +125,9 @@ def test_raises(self, tasmax_series, tasmin_series): arr = series(vals, start="1971-01-01") bad_ds = xr.merge([bad_ds, arr]) + # At this stage, it should not raise an exception + df.data_flags(bad_ds.tasmax, bad_ds, raise_flags=True) + # Swap entire variable arrays bad_ds["tasmin"].values, bad_ds["tasmax"].values = ( bad_ds.tasmax.values, diff --git a/xclim/core/dataflags.py b/xclim/core/dataflags.py index 494e124dc..9953d0371 100644 --- a/xclim/core/dataflags.py +++ b/xclim/core/dataflags.py @@ -692,7 +692,7 @@ def _missing_vars(function, dataset: xarray.Dataset, var_provided: str): dsflags = xarray.Dataset(data_vars=flags) if raise_flags: - if np.any(dsflags.data_vars.values()): + if np.any([flags[dv] for dv in flags.data_vars]): raise DataQualityException(dsflags) return dsflags From 056edb2fa6241adfc66fc7beb24f3dc83807222b Mon Sep 17 00:00:00 2001 From: RondeauG Date: Wed, 16 Aug 2023 15:18:27 -0400 Subject: [PATCH 2/4] upd CHANGES --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index 9e1ffb508..220845c89 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -20,6 +20,7 @@ Bug fixes * Fix the registry entries of "generic" indicators. (:issue:`1423`, :pull:`1424`). * Fix `jetstream_metric_woollings` so it uses the `vertical` coordinate identified by `cf-xarray`, instead of `pressure`. (:issue:`1421`, :pull:`1422`). Add logic to handle coordinates in decreasing order, or for longitudes defined from 0-360 instead of -180 to 180. (:issue:`1429`, :pull:`1430`). * Fix virtual indicator attribute assignment causing individual indicator's realm to be ignored. (:issue:`1425`, :pull:`1426`). +* Fixes the `raise_flags` argument of ``xclim.core.dataflags.data_flags`` so that an Exception is only raised when some checkups fail (:issue:`1456`, :pull:`1457`). Internal changes ^^^^^^^^^^^^^^^^ From be7ceec7e4cacb59be6bf76b45492317cc6cc26e Mon Sep 17 00:00:00 2001 From: RondeauG Date: Wed, 16 Aug 2023 15:29:34 -0400 Subject: [PATCH 3/4] fix copy-paste --- xclim/core/dataflags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xclim/core/dataflags.py b/xclim/core/dataflags.py index 9953d0371..6ddbde005 100644 --- a/xclim/core/dataflags.py +++ b/xclim/core/dataflags.py @@ -692,7 +692,7 @@ def _missing_vars(function, dataset: xarray.Dataset, var_provided: str): dsflags = xarray.Dataset(data_vars=flags) if raise_flags: - if np.any([flags[dv] for dv in flags.data_vars]): + if np.any([dsflags[dv] for dv in dsflags.data_vars]): raise DataQualityException(dsflags) return dsflags From 3d5a6872da9bfd6fed1d19402faad86f4f2c1fc6 Mon Sep 17 00:00:00 2001 From: RondeauG Date: Wed, 16 Aug 2023 15:53:26 -0400 Subject: [PATCH 4/4] fix typos --- xclim/core/dataflags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xclim/core/dataflags.py b/xclim/core/dataflags.py index 6ddbde005..9b1773c43 100644 --- a/xclim/core/dataflags.py +++ b/xclim/core/dataflags.py @@ -559,7 +559,7 @@ def data_flags( The value can be None if there are no parameters to pass (i.e. default will be used). The default, None, means that the data flags list will be taken from :py:obj:`xclim.core.utils.VARIABLES`. dims : {"all", None} or str or a sequence of strings - Dimenions upon which aggregation should be performed. Default: "all". + Dimensions upon which the aggregation should be performed. Default: "all". freq : str, optional Resampling frequency to have data_flags aggregated over periods. Defaults to None, which means the "time" axis is treated as any other dimension (see `dims`).