Unidata / cftime

Time-handling functionality from netcdf4-python.

Home Page:https://unidata.github.io/cftime

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

date2num error when converting a DatetimeProlepticGregorian object in cftime 1.0.4

spencerkclark opened this issue · comments

In version 1.0.3.4 of cftime the following succeeds without an error:

In [1]: import cftime

In [2]: d = cftime.DatetimeProlepticGregorian(1, 1, 1)

In [3]: cftime.date2num(d, 'days since 0001-01-01', 'proleptic_gregorian')
Out[3]: 0.0

However, with 1.0.4, the following occurs:

In [3]: cftime.date2num(d, 'days since 0001-01-01', 'proleptic_gregorian')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-5b0bfcafe058> in <module>
----> 1 cftime.date2num(d, 'days since 0001-01-01', 'proleptic_gregorian')

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

AttributeError: 'cftime._cftime.DatetimeProlepticGregorian' object has no attribute 'tzinfo'

We came across this in the xarray test suite, xref: pydata/xarray#3427. Was this an intentional change?

Seems to be related to

#110

@barronh, could you take a look?

Looks like a simple fix for a typo that slipped through in PR #110 (PR #127). Assuming the xarray test suite runs cleanly with this fix, I'll push a 1.0.4.1 release.

I’m at a conference thru tomorrow, so I haven’t been able to look at it. I trust that you’re right. I could look on Thursday.

Will go ahead and merge since the fix is trivial.