Skip to content

Commit

Permalink
skip missing check if no time in variable (#382)
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 #xyz
- [x] (If applicable) Documentation has been added / updated (for bug
fixes / features).
- [x] (If applicable) Tests have been added.
- [x] This PR does not seem to break the templates.
- [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?

* Added a check to make sure that the `time` dimension exists for the
variable before checking for missing data.

### Does this PR introduce a breaking change?

* No.

### Other information:
  • Loading branch information
RondeauG authored Apr 12, 2024
2 parents e1b2d52 + c824a91 commit 3256717
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Bug fixes
* `creep_weights` now correctly handles the case where the grid is small, `n` is large, and `mode=wrap`. (:issue:`367`).
* Fixed a bug in ``tasmin_from_dtr`` and ``tasmax_from_dtr``, when `dtr` units differed from tasmin/max. (:pull:`372`).
* Fixed a bug where the requested chunking would be ignored when saving a dataset (:pull:`379`).
* The missing value check in ``health_checks`` will no longer crasg if a variable has no time dimension. (:pull:`382`).

v0.8.3 (2024-02-28)
-------------------
Expand Down
15 changes: 10 additions & 5 deletions xscen/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,16 @@ def _message():
for method, kwargs in missing.items():
kwargs.setdefault("freq", "YS")
for v in ds.data_vars:
ms = getattr(xc.core.missing, method)(ds[v], **kwargs)
if ms.any():
_error(
f"The variable '{v}' has missing values according to the '{method}' method.",
"missing",
if "time" in ds[v].dims:
ms = getattr(xc.core.missing, method)(ds[v], **kwargs)
if ms.any():
_error(
f"The variable '{v}' has missing values according to the '{method}' method.",
"missing",
)
else:
logger.info(
f"Variable '{v}' has no time dimension. The missing data check will be skipped.",
)

if flags is not None:
Expand Down

0 comments on commit 3256717

Please sign in to comment.