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

Remove in-house long time interval checking. #279

Merged
merged 6 commits into from
Oct 12, 2023

Conversation

trexfeathers
Copy link
Collaborator

🚀 Pull Request

Description

Closes #274. Removes cf-units' own checking for long time intervals that might prevent certain operations.

This was introduced in #72, but cftime (previously netcdftime) continues to improve handling of long time intervals, and has a more informative error when they can't be handled. This makes our own checking superfluous and also overzealous.

I have removed all tests concerning long time interval errors, since it would be inappropriate for our tests to depend on the behaviour of cftime.

If this change is accepted: a sister PR on Iris will also be needed, since Iris includes some defensive coding to avoid failure when printing an invalid time Unit - iris.coords#L346. To allow for cftime's continuing improvements - including tolerance for previously invalid time spacings - it would be safest to use try-except during the printing rather than a more specific check.

Demonstration
my_unit = Unit("months since 2010-01-01", calendar="standard")
print(my_unit.num2date(3))
Traceback (most recent call last):
  File "/tmp/persistent/repos/cf-units/tmp_long.py", line 4, in <module>
    print(my_unit.num2date(3))
  File "/tmp/persistent/repos/cf-units/cf_units/__init__.py", line 2043, in num2date
    return _num2date_to_nearest_second(
  File "/tmp/persistent/repos/cf-units/cf_units/__init__.py", line 564, in _num2date_to_nearest_second
    dates = cftime.num2date(time_values, **num2date_kwargs)
  File "src/cftime/_cftime.pyx", line 499, in cftime._cftime.num2date
  File "src/cftime/_cftime.pyx", line 99, in cftime._cftime._dateparse
ValueError: 'months since' units only allowed for '360_day' calendar


my_unit = Unit("months since 2010-01-01", calendar="360_day")
print(my_unit.num2date(3))
2010-04-01 00:00:00

pp-mo
pp-mo previously requested changes Aug 22, 2022
Copy link
Member

@pp-mo pp-mo left a comment

Choose a reason for hiding this comment

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

Otherwise all looks good

cf_units/__init__.py Outdated Show resolved Hide resolved
@bjlittle
Copy link
Member

bjlittle commented Aug 2, 2023

@trexfeathers ping (if you get time) 😉

@trexfeathers trexfeathers reopened this Aug 2, 2023
@trexfeathers
Copy link
Collaborator Author

@pp-mo I forgot about this, but it is now ready to merge. It would also fix at least 1 Iris issue. Could you take a quick look? Thanks!

Copy link
Member

@bjlittle bjlittle left a comment

Choose a reason for hiding this comment

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

@trexfeathers Awesome, thanks! 😄

Just a minor tweak and we're good to go 👍

cf_units/__init__.py Outdated Show resolved Hide resolved
@bjlittle bjlittle dismissed pp-mo’s stale review October 12, 2023 10:45

Review actions have been serviced

@bjlittle bjlittle merged commit b8d8bfc into SciTools:main Oct 12, 2023
12 checks passed
@trexfeathers
Copy link
Collaborator Author

Thanks for getting this over the line @bjlittle!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Align long time interval check with cftime
3 participants