Skip to content

Commit

Permalink
Fix raise_flags (#1457)
Browse files Browse the repository at this point in the history
<!--Please ensure the PR fulfills the following requirements! -->
<!-- If this is your first PR, make sure to add your details to the
AUTHORS.rst! -->
### Pull Request Checklist:
- [x] This PR addresses an already opened issue (for bug fixes /
features)
    - This PR fixes #1456
- [x] Tests for the changes have been added (for bug fixes / features)
- [x] (If applicable) Documentation has been added / updated (for bug
fixes / features)
- [x] CHANGES.rst has been updated (with summary of main changes)
- [x] Link to issue (:issue:`number`) and pull request (:pull:`number`)
has been added

### What kind of change does this PR introduce?

* Fixes the `raise_flags` argument of `xclim.core.dataflags.data_flags`
so that an Exception is only raised when some checkups fail.

### Does this PR introduce a breaking change?

- No

### Other information:
  • Loading branch information
RondeauG committed Aug 17, 2023
2 parents 7451885 + 3d5a687 commit cb76d3c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
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

0 comments on commit cb76d3c

Please sign in to comment.