Skip to content

Commit

Permalink
Merge pull request #257 from Unidata/issue256
Browse files Browse the repository at this point in the history
address deprecation of calendar='gregorian' in CF v1.9 (issue #256)
  • Loading branch information
jswhit authored Nov 25, 2021
2 parents 4d696fb + 1b2972d commit a47efb5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/miniconda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [ "3.7", "3.8", "3.9"]
python-version: [ "3.7", "3.8", "3.9", "3.10"]
os: [windows-latest, ubuntu-latest, macos-latest]
platform: [x64, x32]
# debug on a single os/platform/python version
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
# coveralls --service=github-actions

- name: Tarball
if: startsWith(matrix.os,'ubuntu')
if: startsWith(matrix.os,'ubuntu') && matrix.python-version == '3.9'
shell: bash -l {0}
run: |
source activate TEST
Expand All @@ -74,7 +74,7 @@ jobs:
twine check dist/* ;
- name: Docs
if: startsWith(matrix.os,'ubuntu')
if: startsWith(matrix.os,'ubuntu') && matrix.python-version == '3.9'
shell: bash -l {0}
run: |
source activate TEST
Expand Down
5 changes: 5 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
version 1.5.2 (not yet released)
================================
* silently change calendar='gregorian' to 'standard' internally,
since 'gregorian' deprecated in CF v1.9 (issue #256).

version 1.5.1.1
===============
* no code changes, just new binary wheels for python 3.10.
Expand Down
14 changes: 7 additions & 7 deletions src/cftime/_cftime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cdef int[12] _dayspermonth_leap = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 3
cdef int[13] _cumdayspermonth = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365]
cdef int[13] _cumdayspermonth_leap = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366]

__version__ = '1.5.1.1'
__version__ = '1.5.2'

# Adapted from http://delete.me.uk/2005/03/iso8601.html
# Note: This regex ensures that all ISO8601 timezone formats are accepted - but, due to legacy support for other timestrings, not all incorrect formats can be rejected.
Expand Down Expand Up @@ -1050,7 +1050,7 @@ The default format of the string produced by strftime is controlled by self.form
if calendar == 'gregorian' or calendar == 'standard':
# dates after 1582-10-15 can be converted to and compared to
# proleptic Gregorian dates
self.calendar = 'gregorian'
self.calendar = 'standard'
if self.to_tuple() >= (1582, 10, 15, 0, 0, 0, 0):
self.datetime_compatible = True
else:
Expand Down Expand Up @@ -1394,7 +1394,7 @@ The default format of the string produced by strftime is controlled by self.form
elif calendar == 'julian':
#return dt.__class__(*add_timedelta(dt, delta, is_leap_julian, False, has_year_zero),calendar=calendar,has_year_zero=has_year_zero)
return DatetimeJulian(*add_timedelta(dt, delta, is_leap_julian, False, has_year_zero),has_year_zero=has_year_zero)
elif calendar == 'gregorian':
elif calendar == 'standard':
#return dt.__class__(*add_timedelta(dt, delta, is_leap_gregorian, True, has_year_zero),calendar=calendar,has_year_zero=has_year_zero)
return DatetimeGregorian(*add_timedelta(dt, delta, is_leap_gregorian, True, has_year_zero),has_year_zero=has_year_zero)
elif calendar == 'proleptic_gregorian':
Expand Down Expand Up @@ -1452,7 +1452,7 @@ datetime object."""
#return self.__class__(*add_timedelta(self, -other,
# is_leap_julian, False, has_year_zero),calendar=self.calendar,has_year_zero=self.has_year_zero)
return DatetimeJulian(*add_timedelta(self, -other, is_leap_julian, False, has_year_zero),has_year_zero=self.has_year_zero)
elif self.calendar == 'gregorian':
elif self.calendar == 'standard':
#return self.__class__(*add_timedelta(self, -other,
# is_leap_gregorian, True, has_year_zero),calendar=self.calendar,has_year_zero=self.has_year_zero)
return DatetimeGregorian(*add_timedelta(self, -other, is_leap_gregorian, True, has_year_zero),has_year_zero=self.has_year_zero)
Expand Down Expand Up @@ -1764,7 +1764,7 @@ cdef _check_calendar(calendar):
raise ValueError('unsupported calendar')
calout = calendar
# remove 'gregorian','noleap','all_leap'
if calendar in 'gregorian':
if calendar == 'gregorian':
calout = 'standard'
if calendar == 'noleap':
calout = '365_day'
Expand Down Expand Up @@ -1922,10 +1922,10 @@ but uses the "julian" calendar.
cdef class DatetimeGregorian(datetime):
"""
Phony datetime object which mimics the python datetime object,
but uses the mixed Julian-Gregorian ("standard", "gregorian") calendar.
but uses the mixed Julian-Gregorian ("standard") calendar.
"""
def __init__(self, *args, **kwargs):
kwargs['calendar']='gregorian'
kwargs['calendar']='standard'
super().__init__(*args, **kwargs)

@cython.embedsignature(True)
Expand Down
16 changes: 7 additions & 9 deletions test/test_cftime.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def adjust_calendar(calendar):
# check for and remove calendar synonyms.
calendar = calendar.lower()
if calendar == 'gregorian' or calendar == 'standard':
return 'gregorian'
return 'standard'
elif calendar == 'noleap' or calendar == '365_day':
return 'noleap'
elif calendar == 'all_leap' or calendar == '366_day':
Expand Down Expand Up @@ -506,7 +506,7 @@ def roundtrip(delta,eps,units):
units = 'days since 0001-01-01'
for cap_cal, low_cal in (('STANDARD', 'standard'),
('NoLeap', 'noleap'),
('Gregorian', 'gregorian'),
('Standard', 'standard'),
('ALL_LEAP', 'all_leap')):
d1 = date2num(d, units, cap_cal)
d2 = date2num(d, units, low_cal)
Expand Down Expand Up @@ -555,15 +555,13 @@ def roundtrip(delta,eps,units):
# n should always be 0 as all units refer to the same point in time
assert_almost_equal(n, 0)

# list around missing dates in Gregorian calendar
# list around missing dates in mixed Julian/Gregorian calendar
# scalar
units = 'days since 0001-01-01 12:00:00'
t1 = date2num(datetime(1582, 10, 4), units, calendar='gregorian')
t2 = date2num(datetime(1582, 10, 15), units, calendar='gregorian')
t1 = date2num(datetime(1582, 10, 4), units, calendar='standard')
t2 = date2num(datetime(1582, 10, 15), units, calendar='standard')
self.assertEqual(t1+1, t2)
# list
t1, t2 = date2num([datetime(1582, 10, 4), datetime(1582, 10, 15)], units, calendar='gregorian')
self.assertEqual(t1+1, t2)
t1, t2 = date2num([datetime(1582, 10, 4), datetime(1582, 10, 15)], units, calendar='standard')
self.assertEqual(t1+1, t2)
# this should fail: days missing in Gregorian calendar
Expand Down Expand Up @@ -860,7 +858,7 @@ def roundtrip(delta,eps,units):
jdref=2400000
with warnings.catch_warnings():
warnings.simplefilter("ignore",category=cftime.CFWarning)
for calendar in ['julian','gregorian','proleptic_gregorian']:
for calendar in ['julian','standard','proleptic_gregorian']:
has_year_zero=False
try:
# this should raise ValueError
Expand Down Expand Up @@ -1652,7 +1650,7 @@ def test_num2date_only_use_cftime_datetimes_post_gregorian(


def test_repr():
expected = "cftime.datetime(2000, 1, 1, 0, 0, 0, 0, calendar='gregorian', has_year_zero=False)"
expected = "cftime.datetime(2000, 1, 1, 0, 0, 0, 0, calendar='standard', has_year_zero=False)"
assert repr(datetimex(2000, 1, 1, calendar='standard')) == expected
expected = "cftime.datetime(2000, 1, 1, 0, 0, 0, 0, calendar='', has_year_zero=False)"
assert repr(datetimex(2000, 1, 1, calendar=None)) == expected
Expand Down

0 comments on commit a47efb5

Please sign in to comment.