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

Bug or feature: malformatted datetimes in time units go unnoticed #216

Open
larsbarring opened this issue Feb 25, 2022 · 0 comments
Open
Labels
community New: Issue Highlight a new community raised "generic" issue Type: Bug

Comments

@larsbarring
Copy link
Contributor

🐛 Bug Report

By incidence I noticed that various "strange" datetimes are accepted:

from cf_units import Unit
unit_str = [
    ("days since 1582-1010", "standard", "Error: generally malformed"),
    ("days since 1582-10-10", "standard", "Warning: date in Julian/Gregorian gap"),
    ("days since 1582-10-10", "julian", "Perfectly fine"),
    ("days since 1582-10-10", "proleptic_gregorian", "Perfectly fine"),
    ("days since haywire", "standard", "Captured error"),
    ("days since epoch", "standard", "Perfectly fine"),
    ("days since 0-0-0", "standard", "Error: wrong month/day"),
    ("days since 0-0-0", "julian", "Error: wrong month/day"),
    ("days since 0-0-0", "proleptic_gregorian", "Error: wrong month/day"),
    ("days since 0-1-1", "standard", "Warning: deprecated 'climatology' indicator"),
    ("days since 0-1-1", "julian", "Warning: deprecated 'climatology' indicator"),
    ("days since 0-1-1", "proleptic_gregorian", "Perfectly fine"),
    ("days since -1-1-1", "standard", "Error: negative year"),
    ("days since -1-1-1", "julian", "Error: negative year"),
    ("days since -1-1-1", "proleptic_gregorian", "Perfectly fine"),
]

for s in unit_str:
    try:
        u = Unit(s[0], calendar=s[1])
    except ValueError as e:
        u = str(e)
    print(f"({s[0]}, {s[1]}  ---> {u}   :   {s[2]}")

(days since 1582-1010, standard  ---> days since 1582-1010   :   Error: generally malformed
(days since 1582-10-10, standard  ---> days since 1582-10-10   :   Warning: date in Julian/Gregorian gap
(days since 1582-10-10, julian  ---> days since 1582-10-10   :   Perfectly fine
(days since 1582-10-10, proleptic_gregorian  ---> days since 1582-10-10   :   Perfectly fine
(days since haywire, standard  ---> [UT_SUCCESS] Failed to parse unit "days since haywire"   :   Captured error
(days since epoch, standard  ---> days since 1970-01-01 00:00:00   :   Perfectly fine
(days since 0-0-0, standard  ---> days since 0-0-0   :   Error: wrong month/day
(days since 0-0-0, julian  ---> days since 0-0-0   :   Error: wrong month/day
(days since 0-0-0, proleptic_gregorian  ---> days since 0-0-0   :   Error: wrong month/day
(days since 0-1-1, standard  ---> days since 0-1-1   :   Warning: deprecated 'climatology' indicator
(days since 0-1-1, julian  ---> days since 0-1-1   :   Warning: deprecated 'climatology' indicator
(days since 0-1-1, proleptic_gregorian  ---> days since 0-1-1   :   Perfectly fine
(days since -1-1-1, standard  ---> days since -1-1-1   :   Error: negative year
(days since -1-1-1, julian  ---> days since -1-1-1   :   Error: negative year
(days since -1-1-1, proleptic_gregorian  ---> days since -1-1-1   :   Perfectly fine

Expected Behaviour

Expected -- or suggested -- behaviour is indicated to the right of each line. These suggestions generally follow CF 1.9, which do not allow negative years for standard and julian calendars (either in the time coordinate or in the unit string), which is different from cftime. If scitools wants to be more permissive negative years could instead result in a warning that this does not conform to CF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community New: Issue Highlight a new community raised "generic" issue Type: Bug
Projects
Status: No status
Status: No status
Development

No branches or pull requests

2 participants