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

Quantified units in call signatures should raise Exception if declare_units with dimensions are not supplied #1293

Closed
Zeitsperre opened this issue Feb 8, 2023 · 0 comments · Fixed by #1393
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Zeitsperre
Copy link
Collaborator

  • xclim version: 0.40.0
  • Python version: Any
  • Operating System: All

Ran into this issue in #1235

It should not be possible to set a call signature within an indice with Quantified without also specifying the dimensions for it within the declare_units decorator. This causes problems with Indicator parameters and feels like an undocumented "gotcha".

e.g. wo in the following call signature should be [length]:

@declare_units(pr="[precipitation]", evspsblpot="[precipitation]")
def dryness_index(
    pr: xarray.DataArray,
    evspsblpot: xarray.DataArray,
    lat: xarray.DataArray | str | None = None,
    wo: Quantified = "200 mm",
    freq: str = "YS",
) -> xarray.DataArray:
...
@Zeitsperre Zeitsperre added the bug Something isn't working label Feb 8, 2023
@Zeitsperre Zeitsperre added this to the Summer 2023 milestone Jun 13, 2023
@huard huard self-assigned this Jun 13, 2023
@huard huard mentioned this issue Jun 13, 2023
5 tasks
huard added a commit that referenced this issue Jun 13, 2023
Make sure all Quantified parameters with a default value declare their
dimension.

<!--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 #1293 
- [x] Tests for the changes have been added (for bug fixes / features)
- [ ] (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?

* Add sanity check in declare_units. 

### 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.

2 participants