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

cftime date2num not working after 15/10/1582. #258

Closed
reos-egoss opened this issue Nov 19, 2021 · 6 comments
Closed

cftime date2num not working after 15/10/1582. #258

reos-egoss opened this issue Nov 19, 2021 · 6 comments

Comments

@reos-egoss
Copy link

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!

@jswhit
Copy link
Collaborator

jswhit commented Nov 19, 2021

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.

@jswhit
Copy link
Collaborator

jswhit commented Nov 20, 2021

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).

@reos-egoss
Copy link
Author

reos-egoss commented Nov 22, 2021 via email

@jswhit
Copy link
Collaborator

jswhit commented Nov 22, 2021

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.

@jswhit
Copy link
Collaborator

jswhit commented Nov 25, 2021

Here's the pendulum bug that is responsible for the error you are seeing.
python-pendulum/pendulum#382
Looks like this module is basically unmaintained at the moment (python-pendulum/pendulum#354)

@reos-egoss
Copy link
Author

reos-egoss commented Nov 25, 2021 via email

@jswhit jswhit closed this as completed Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants