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 data flags var name generation #1507

Merged
merged 2 commits into from
Oct 23, 2023
Merged

Fix data flags var name generation #1507

merged 2 commits into from
Oct 23, 2023

Conversation

aulemahal
Copy link
Collaborator

Pull Request Checklist:

  • This PR addresses an already opened issue (for bug fixes / features)
    • This PR fixes a issue raised in private communication by @RondeauG
  • 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?

Changes how the data flags variable names are generated.

In the previous version, every kwargs was sent to str2pint. We were relying on a try: except to catch those kwargs that weren't quantities. This had the caveat of requiring an explicit list of possible errors. @RondeauG had a case where op='>=' was triggering a ValueError, which wasn't listed.

I changed this "implicit" parsing to an "explicit" one:

  • Data flags declare the variable name as a templated string.
  • Parameters are iterated through and handled according to their "InputKind"
    • "Quantified" inputs are handled as before, but all others are passed as-is.

This required:

  • Changing the registering decorator to accept a templated string argument
  • Correctly annotating the inputs, which lead to adding missing thresholds to the declared units

Does this PR introduce a breaking change?

Yes, I made the arbitrary choice of changing how we stringify the minus sign:

Input thresh : -5.1 mm
Template : "values_greater_{thresh}"
Before : "values_greater__minus_5point1"
This PR: "values_greater_minus5point1"

However, I don't think this will affect many projects.

Other information:

@RondeauG , could you try this new branch with your code ? (That's why I made you a reviewer)

@aulemahal aulemahal changed the title fix Data flags var name generation Fix data flags var name generation Oct 20, 2023
Copy link
Collaborator

@Zeitsperre Zeitsperre left a comment

Choose a reason for hiding this comment

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

LGTM. Nice to see existing functions being used to handle signatures.

@@ -97,7 +108,7 @@ def _sanitize_attrs(da: xarray.DataArray) -> xarray.DataArray:
return da


@register_methods
@register_methods()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are parentheses needed here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a decorator level to the function: @register_methods() actually returns the real decorator, using the default value (None, thus func.__name__) as variable name.

Copy link
Collaborator

@Zeitsperre Zeitsperre Oct 20, 2023

Choose a reason for hiding this comment

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

I don't quite understand, but I'll give it a look on Monday with fresher eyes.

@github-actions github-actions bot added the approved Approved for additional tests label Oct 20, 2023
@aulemahal aulemahal merged commit 7edffda into master Oct 23, 2023
12 checks passed
@aulemahal aulemahal deleted the fix-dataflags-naming branch October 23, 2023 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Approved for additional tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants