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

raise_flags in dataflags is always raised #1456

Closed
2 tasks done
RondeauG opened this issue Aug 16, 2023 · 0 comments · Fixed by #1457
Closed
2 tasks done

raise_flags in dataflags is always raised #1456

RondeauG opened this issue Aug 16, 2023 · 0 comments · Fixed by #1457
Labels
bug Something isn't working

Comments

@RondeauG
Copy link
Contributor

RondeauG commented Aug 16, 2023

Setup Information

  • Xclim version: 0.44

Description

When using xclim.core.dataflags.data_flags, an exception will always be raised when raise_flags=True.

Steps To Reproduce

import numpy as np
import xclim.core.dataflags
from xclim.testing.helpers import test_timeseries as timeseries
tasmin = np.array([-15] * 365)
tasmax = np.array([15] * 365)
ds = timeseries(tasmin, "tasmin", "1/1/2000", freq="D", as_dataset=True)
ds["tasmax"] = timeseries(tasmax, "tasmax", "1/1/2000", freq="D")
flags = {"tasmax_below_tasmin": {}}
xclim.core.dataflags.data_flags(ds["tasmax"], ds, flags=flags, raise_flags=True)

Gives:

Traceback (most recent call last):
  File "/usr/local/pycharm-community-2022.2.3/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
  File "/.../site-packages/xclim/core/dataflags.py", line 696, in data_flags
    raise DataQualityException(dsflags)
xclim.core.dataflags.DataQualityException: Data quality flags indicate suspicious values. Flags raised are:
  - 

Additional context

I'm pretty sure that the culprit is

if np.any(dsflags.data_vars.values()):

It currently gives:

ValuesView(Data variables:
    tasmax_below_tasmin  bool False)

Which I'm guessing gets interpreted as a True. Something like np.any([dsflags[v].values for v in dsflags.data_vars]) would give the correct False.

Contribution

  • I would be willing/able to open a Pull Request to address this bug.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@RondeauG RondeauG added the bug Something isn't working label Aug 16, 2023
RondeauG added a commit that referenced this issue Aug 17, 2023
<!--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:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant