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 in strftime(): "unsupported calendar" #169

Closed
davidhassell opened this issue May 6, 2020 · 8 comments
Closed

Bug in strftime(): "unsupported calendar" #169

davidhassell opened this issue May 6, 2020 · 8 comments

Comments

@davidhassell
Copy link
Contributor

Hello,

I think I found a bug (or feature?) in strftime, that was introduced in 1.1.2 and is causing failures in my code:

All is well at 1.1.1.2:

In [1]: import cftime                                                                                       

In [2]: cftime.__version__                                                                                  
Out[2]: '1.1.1.2'

In [3]: c = cftime.datetime(*cftime._parse_date('7480-01-01 00:00:00')) 

In [4]: c.strftime()                                                                                        
Out[4]: '7480-01-01 00:00:00'

In [5]: c.calendar                                                               
Out[5]: ''

But not at 1.1.2

In [8]: import cftime

In [9]: cftime.__version__
Out[9]: '1.1.2'

In [10]: c = cftime.datetime(*cftime._parse_date('7480-01-01 00:00:00'))

In [11]: c.strftime()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-11-a934a194dce4> in <module>()
----> 1 c.strftime()

cftime/_cftime.pyx in cftime._cftime.datetime.strftime()

cftime/_cftime.pyx in cftime._cftime._strftime()

cftime/_cftime.pyx in cftime._cftime.datetime.timetuple()

cftime/_cftime.pyx in cftime._cftime.datetime.dayofyr.__get__()

cftime/_cftime.pyx in cftime._cftime.JulianDayFromDate()

cftime/_cftime.pyx in cftime._cftime._IntJulianDayFromDate()

cftime/_cftime.pyx in cftime._cftime._check_calendar()

ValueError: unsupported calendar

In [12]: 

In [13]: c.calendar                                                               
Out[5]: ''

I know that '' is not a valid calendar, but this worked as I expected in the previous version.

As this relates to the recent work that went into 1.1.2, I thought I'd raise it here first before suggesting a fix, but I am happy to investigate further if that helps.

Many thanks,
David

@jswhit2
Copy link
Contributor

jswhit2 commented May 6, 2020

This seems to be related to the change that made dayofyr a property instead of an attribute. Since that calculation requires a calendar I don't see an obvious simple fix.

@jswhit2
Copy link
Contributor

jswhit2 commented May 6, 2020

I guess one solution would be to make the default cftime.datetime calendar proleptic_gregorian (or standard) instead of an empty string.

jswhit added a commit that referenced this issue May 6, 2020
@jswhit
Copy link
Collaborator

jswhit commented May 6, 2020

Fix in PR #170

@davidhassell
Copy link
Contributor Author

davidhassell commented May 7, 2020

That sounds like a good solution - thanks for the quick fix! I think I'd prefer standard, though, rather than proleptic_gregorian, as that is the CF conventions default calendar. Is that OK?

@jswhit
Copy link
Collaborator

jswhit commented May 7, 2020

The reason I went with proleptic_gregorian was so that cftime.datetime instances would behave like python datetime instances by default. However, I see why you would prefer standard since it's the most commonly used netcdf calendar.

@jswhit
Copy link
Collaborator

jswhit commented May 7, 2020

Changed it to standard, since that's the default calendar for everything else.

@davidhassell
Copy link
Contributor Author

Thanks - that's good for me.

jswhit added a commit that referenced this issue May 7, 2020
@jswhit
Copy link
Collaborator

jswhit commented May 7, 2020

PR #170 merged. I will push out a 1.1.3 release soon, since this is a pretty significant bug.

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

3 participants