-
Notifications
You must be signed in to change notification settings - Fork 39
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
date2num conversion wrong for (some) python datetimes #354
Comments
I believe this is the correct answer, since the 'standard' calendar switches from julian to gregorian in 1582, skipping two calendar days. |
How do you explain the difference in the second example between python.datetime (dates1) and cftime.datetime (update: dates3) which both use proleptic_gregorian calendar? |
You will get the answer you expect if you change the calendar kwarg to 'calendar2' in
|
ignore the previous comment - the calendar kwarg should override the calendar associated with the datetime instances. |
I'm thinking that when I provide python datetime.datetime date2num just assumes "proleptic_gregorian" instead of using the wanted "standard" calendar. For the cftime.datetime(..., calendar="proleptic_gregorian") this works instead as intended. Update: to make the above more clear and simple import datetime
import cftime
dt1a = cftime.datetime(2, 1, 1, calendar="proleptic_gregorian")
num1 = cftime.date2num(dt1a, "seconds since 2000-01-01", "standard")
dt1b = cftime.num2date(num1, "seconds since 2000-01-01", "standard")
dt2a = datetime.datetime(2, 1, 1)
num2 = cftime.date2num(dt2a, "seconds since 2000-01-01", "standard")
dt2b = cftime.num2date(num2, "seconds since 2000-01-01", "standard")
print(dt1a, num1, dt1b)
print(dt2a, num2, dt2b) 0002-01-01 00:00:00 -63050918400 0002-01-01 00:00:00
0002-01-01 00:00:00 -63050745600 0002-01-03 00:00:00 |
Yes, I think you are correct. I think this is a bug, since it works as expected if you give it an array of cftime.datetime instances with the proleptic_gregorian calendar. |
This should now be fixed in master with the merging of PR #355 |
Thanks @jswhit for the quick fix! |
To report a non-security related issue, please provide:
the version of the software with which you are encountering an issue
cftime v1.6.4
environmental information (i.e. Operating System, compiler info, java version, python version, etc.)
I'm trying to wrap my head around how cftime converts datetimes of different provencience to the numerical representation (via cftime.date2num). First a working example with python datetime and cftime datetime with standard and proleptic gregorian calendars. The output is as expected, two proleptic_gregorian and one standard calendar. Also the roundtrip works, when using the appropriate calendar.
Output
Now, when selecting the output calendar this doesn't work anymore and a shift of two days occur for the python datetimes in the roundtrip:
Output
I'd expect that cftime correctly converts the python datetimes to the wanted output calendar. I did not find anything related in the documentation so any pointers are welcome.
The text was updated successfully, but these errors were encountered: