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 freq/offset/indexer attrs in SPI #1538

Merged
merged 12 commits into from Dec 1, 2023
Merged

fix freq/offset/indexer attrs in SPI #1538

merged 12 commits into from Dec 1, 2023

Conversation

coxipi
Copy link
Contributor

@coxipi coxipi commented Nov 24, 2023

Pull Request Checklist:

  • This PR addresses an already opened issue (for bug fixes / features)
    • This PR fixes #xyz
  • Tests for the changes have been added (for bug fixes / features)
    • (If applicable) Documentation has been added / updated (for bug fixes / features)
  • CHANGES.rst has been updated (with summary of main changes)
    • Link to issue (:issue:number) and pull request (:pull:number) has been added

What kind of change does this PR introduce?

  • Fixes wrong attributes in SPI/SPEI functions, allow to save files in netcdf files.

Does this PR introduce a breaking change?

No

Other information:

@github-actions github-actions bot added the indicators Climate indices and indicators label Nov 24, 2023
xclim/indices/stats.py Outdated Show resolved Hide resolved
@coveralls
Copy link

Coverage Status

coverage: 89.815%. first build
when pulling 78fef68 on fix_spi_attrs
into d382912 on master.

@@ -660,7 +660,7 @@ def standardized_index_fit_params(
window: int,
dist: str,
method: str,
offset: Quantified | None = None,
offset: Quantified = "",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: I don't really understand what the original issue is.

In indices/_conversion.py, there are a lot of instances of a Quantified parameter set to None. I suspect it would be best to have consistency in how we represent default null Quantified values.

Would doing something like
offset = offset or ""
let you keep None as the default but not mess with attribute records?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's a good way around, I'll adopt this instead, thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original issue was what you describe, None and {} mess the attributes records, an array can'T be saved in netcdf. So I wanted to change the default values in the code (so that what is used in the code would be the same thing as in attrs), but as you suggest, simply changing was is stored in the attrs but keep using None in the rest of the code is also possible.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to do the same with other indices ?

Copy link
Collaborator

@aulemahal aulemahal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Copy link
Collaborator

@aulemahal aulemahal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woups

@github-actions github-actions bot added the approved Approved for additional tests label Dec 1, 2023
@coxipi coxipi merged commit d6f09d4 into master Dec 1, 2023
54 of 56 checks passed
@coxipi coxipi deleted the fix_spi_attrs branch December 1, 2023 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Approved for additional tests indicators Climate indices and indicators
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants