-
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
cftime date2num not working after 15/10/1582. #258
Comments
Can you provide the input to cftime.date2num that triggers the crash? For example, import cftime
d = cftime.datetime(1582,10,16,calendar='standard')
n = cftime.date2num(d, "seconds since 1970-01-01 00:00:00.000")
print(n)
-12219206400 works as expected for me. |
could it be that you are trying to use a date that doesn't exist in the 'standard' calendar? (anything between 1582-10-5 00UTC and 1582-10-15 00UTC). |
Hi,
Sorry for the delay in my response.
Your example test runs for me as well and after further investigation I found it only doesn't work after 1582 when using a datetime created using pendulum. I have written a work around now, but I thought you still might be interested to know when it doesn't work. Below is a sample input.
import pendulum
import cftime
t = pendulum.from_format("2021/11/02 00:00:00", "YYYY/MM/DD HH:mm:ss")
p = cftime.date2num(t, "seconds since 1970-01-01 00:00:00.000", calendar="standard")
Does not work, fails with the error: AttributeError: 'datetime.timedelta' object has no attribute '_to_microseconds'
p1 = cftime.date2num(t, "seconds since 1582-01-01 00:00:00.000", calendar="standard")
Works perfectly
Enjoy your week
Emma
On Friday, November 19, 2021 21:42 GMT, Jeff Whitaker ***@***.***> wrote:
Can you provide the input to cftime.date2num that triggers the crash? For example,import cftime
d = cftime.datetime(1582,10,16,calendar='standard'))
n = cftime.date2num(d, "seconds since 1970-01-01 00:00:00.000", calendar="standard")
print(n)
works as expected for me.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
Hmm. The pendulum docs say that pendulum.datetime and timedelta should be drop-in replacements for the built-in versions. Apparently the timedelta object is not. Looks to me this may be a bug in pendulum. |
Here's the pendulum bug that is responsible for the error you are seeing. |
Thank you!
On Thursday, November 25, 2021 01:18 GMT, Jeff Whitaker ***@***.***> wrote:
Here's the pendulum bug that is responsible for the error you are seeing.
python-pendulum/pendulum#382
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
I am using cftime 1.5.1.1 in python 3.8.10 on ubuntu 20.04.
I am trying to change the unit in cftime.date2num from "days since 0001-12-31" to "seconds since 1970-01-01"
The error I am encountering is;
Traceback (most recent call last):
File "/home/egoss/Documents/data_processing/mita-teknik/main.py", line 136, in
daily_dataframe = Txt.input_txt(day[0][1], zipObj)
File "/home/egoss/Documents/data_processing/mita-teknik/Txt_folder.py", line 229, in input_txt
df[set_header[0]] = cftime.date2num(df[set_header[0]], "seconds since 1970-01-01 00:00:00.000", calendar="standard")
File "src/cftime/_cftime.pyx", line 270, in cftime._cftime.date2num
File "/home/egoss/.local/lib/python3.8/site-packages/pendulum/period.py", line 340, in mod
return self.as_interval().mod(other)
File "/home/egoss/.local/lib/python3.8/site-packages/pendulum/duration.py", line 403, in mod
r = self._to_microseconds() % other._to_microseconds()
AttributeError: 'datetime.timedelta' object has no attribute '_to_microseconds'
I have noticed that line 229 does not have any issues if I use a date up to and including 1582-10-15 (the date of the gregorian calendar change.) Any date after this does not work.
Thank you!
The text was updated successfully, but these errors were encountered: