Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix raise_flags #1457

Merged
merged 4 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^
Expand Down
3 changes: 3 additions & 0 deletions tests/test_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions xclim/core/dataflags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down Expand Up @@ -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([dsflags[dv] for dv in dsflags.data_vars]):
raise DataQualityException(dsflags)

return dsflags
Expand Down