ESMValGroup / ESMValCore

ESMValCore: A community tool for pre-processing data from Earth system models in CMIP and running analysis scripts.
https://www.esmvaltool.org
Apache License 2.0
42 stars 38 forks source link

Update adjust time #2490

Open malininae opened 1 month ago

malininae commented 1 month ago

This is update of the extract_time preprocessor to make the start_year and end_year optional (aka None). For reasons, see #2304.

Since extract_time is a very common preprocessor, I didn't want to tinker with the order of the input parameters not to make it backwards incompatible. Currently, if the start_year and end_year need to be None, one needs to explicitly specify it into the preprocessor like this:

    extract_time:
        start_year: null
        start_month: 3
        start_day: 1
        end_year: null
        end_month: 7
        end_day: 14

However, another possibility I see, how one can make the default year input as None, to make the default start_month=1, start_day=1, end_month=12, end_day=31. I will leave it to the others to decide. Based on the speed comment from @bouweandela, I kept the original code as much as possible.

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 97.14286% with 4 lines in your changes missing coverage. Please review.

Project coverage is 94.77%. Comparing base (21ce35a) to head (20ffb97).

Files with missing lines Patch % Lines
esmvalcore/preprocessor/_time.py 97.14% 4 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #2490 +/- ## ======================================= Coverage 94.77% 94.77% ======================================= Files 249 249 Lines 14081 14087 +6 ======================================= + Hits 13345 13351 +6 Misses 736 736 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

malininae commented 1 month ago

@valeriupredoi the codacy checks fail not on my code, but I guess it popped up because I opened it in VSCode which possibly changed formatting. Should I correct it? Or someone else will do it?

malininae commented 1 month ago

looking good! Many thanks, Liza! Could you also add a section in the documentaion about this please? It's a nifty feature that'd be nice to have a few words about it in the documentation, as well as the API docs 🍺

Absolutely, where do you think it would be best to be added? I thought it would come through API only, but I'm happy to elaborate, just not sure where :-)

valeriupredoi commented 1 month ago

looking good! Many thanks, Liza! Could you also add a section in the documentaion about this please? It's a nifty feature that'd be nice to have a few words about it in the documentation, as well as the API docs 🍺

Absolutely, where do you think it would be best to be added? I thought it would come through API only, but I'm happy to elaborate, just not sure where :-)

Liza, there are a few place where a note about this can be nested in:

valeriupredoi commented 1 month ago

@schlunma it'd be good if you had a second look at this when Liza is all done adding a wee bit of documentation too - it's not 100% clear to me if this will play well with ICON data time gating :beer:

schlunma commented 1 month ago

@malininae would it be possible to revert the changes made by your formatter? This makes it really hard to review 😬

At some point we might apply a formatter to the entire code base, so people could simply use them without the risk of reformatting non-related parts of the code. See also https://github.com/ESMValGroup/ESMValTool/discussions/2161.

Thanks!!

bouweandela commented 4 weeks ago

looking good! Many thanks, Liza! Could you also add a section in the documentaion about this please? It's a nifty feature that'd be nice to have a few words about it in the documentation, as well as the API docs 🍺

Absolutely, where do you think it would be best to be added? I thought it would come through API only, but I'm happy to elaborate, just not sure where :-)

The documentation that needs to be updated is here: https://docs.esmvaltool.org/projects/ESMValCore/en/latest/recipe/preprocessor.html#extract-time as also described in our contribution guidelines here: https://docs.esmvaltool.org/projects/ESMValCore/en/latest/contributing.html#what-should-be-documented

malininae commented 3 weeks ago

looking good! Many thanks, Liza! Could you also add a section in the documentaion about this please? It's a nifty feature that'd be nice to have a few words about it in the documentation, as well as the API docs 🍺

Absolutely, where do you think it would be best to be added? I thought it would come through API only, but I'm happy to elaborate, just not sure where :-)

The documentation that needs to be updated is here: https://docs.esmvaltool.org/projects/ESMValCore/en/latest/recipe/preprocessor.html#extract-time as also described in our contribution guidelines here: https://docs.esmvaltool.org/projects/ESMValCore/en/latest/contributing.html#what-should-be-documented

Thanks @bouweandela. As far as I understood, sphinx grabs the documentation for the preprocessor functions from the docstrings. I looked at what was built and the updated parameter texts are there. @valeriupredoi I looked and are you sure there is a sense to add it to datasets? It's just in a preprocessor function, not at the timerange part. At the same time, happy to add if you think it's necessary.

malininae commented 3 weeks ago

@schlunma @valeriupredoi the formatting issue seemed to be resolved by updating the branch.

schlunma commented 2 weeks ago

No, unfortunately the changes are still there. I think you only actively changed the extract_time code, but when you look in the "Files changed" tab from this PR, you'll see that there are lots of changes not related to that.

Merging main into this won't fix it, you'll need to adapt it manually (either by reverting line by line or by restoring the original file from main and then re-adding you're desired code changes). Please make sure to not run the code formatter (yapf?) after making these changes.

bouweandela commented 3 days ago

Thanks @bouweandela. As far as I understood, sphinx grabs the documentation for the preprocessor functions from the docstrings. I looked at what was built and the updated parameter texts are there.

The docstrings are used to build the API docs page here, but you'll also need to update the page that describes how to use this preprocessor function from a recipe: https://github.com/ESMValGroup/ESMValCore/blob/21ce35a73336075e022d65fd867e1e50d6780bff/doc/recipe/preprocessor.rst?plain=1#L1307-L1325 / https://docs.esmvaltool.org/projects/ESMValCore/en/latest/recipe/preprocessor.html#extract-time

bouweandela commented 3 days ago

Please make sure to not run the code formatter (yapf?) after making these changes.

It looks like the pre-commit hooks are not playing nice in this case. Maybe we should discuss this again in the @ESMValGroup/technical-lead-development-team team to see how we can make this more smooth. I usually stage my files for committing by e.g. running git add -u and then run git diff --staged | yapf-diff -i to only format the diff, or I do run the pre-commit hooks and then select only some changes for committing by running git add -p. That works, but it's clunky and not what new contributors expect. Just being able to use pre-commit and be done with it would be much nicer. See also ESMValGroup/ESMValTool#2161.

@schlunma Until we have fixed our automated formatting and pre-commit hooks, I would suggest that reviewers of pull requests are lenient about formatting changes and take a bit of extra trouble to review those too. Would that work for you?

malininae commented 2 days ago

Please make sure to not run the code formatter (yapf?) after making these changes.

It looks like the pre-commit hooks are not playing nice in this case. Maybe we should discuss this again in the @ESMValGroup/technical-lead-development-team team to see how we can make this more smooth. I usually stage my files for committing by e.g. running git add -u and then run git diff --staged | yapf-diff -i to only format the diff, or I do run the pre-commit hooks and then select only some changes for committing by running git add -p. That works, but it's clunky and not what new contributors expect. Just being able to use pre-commit and be done with it would be much nicer. See also ESMValGroup/ESMValTool#2161.

@schlunma Until we have fixed our automated formatting and pre-commit hooks, I would suggest that reviewers of pull requests are lenient about formatting changes and take a bit of extra trouble to review those too. Would that work for you?

Thanks @bouweandela and @schlunma, do I understand correctly, that you want me to revert to the old red changes even though the checks passed? I was thinking, I did ran yapf back in the day, could that be it who screwed stuff up? Is there a way to make the code (I guess pylint compatible?) with running some sort of formatter? I tried ruff (didn't suggest any changes) and black, who made things much worse even with options of shorter lines and py310 as a target. image