Skip to content

Commit cd8e370

Browse files
spencerkclarkshoyer
authored andcommitted
'standard' now refers to 'gregorian' in cftime_range (#2771)
1 parent 17fa64f commit cd8e370

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

doc/whats-new.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ Bug fixes
9494
- Masking data arrays with :py:meth:`xarray.DataArray.where` now returns an
9595
array with the name of the original masked array (:issue:`2748` and :issue:`2457`).
9696
By `Yohai Bar-Sinai <https://github.com/yohai>`_.
97+
- Per `CF conventions
98+
<http://cfconventions.org/cf-conventions/cf-conventions.html#calendar>`_,
99+
specifying ``'standard'`` as the calendar type in
100+
:py:meth:`~xarray.cftime_range` now correctly refers to the ``'gregorian'``
101+
calendar instead of the ``'proleptic_gregorian'`` calendar (:issue:`2761`).
102+
97103
.. _whats-new.0.11.3:
98104

99105
v0.11.3 (26 January 2019)

xarray/coding/cftime_offsets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def get_date_type(calendar):
6868
'proleptic_gregorian': cftime.DatetimeProlepticGregorian,
6969
'julian': cftime.DatetimeJulian,
7070
'all_leap': cftime.DatetimeAllLeap,
71-
'standard': cftime.DatetimeProlepticGregorian
71+
'standard': cftime.DatetimeGregorian
7272
}
7373
return calendars[calendar]
7474

@@ -679,9 +679,9 @@ def cftime_range(start=None, end=None, periods=None, freq='D',
679679
+--------------------------------+---------------------------------------+
680680
| Alias | Date type |
681681
+================================+=======================================+
682-
| standard, proleptic_gregorian | ``cftime.DatetimeProlepticGregorian`` |
682+
| standard, gregorian | ``cftime.DatetimeGregorian`` |
683683
+--------------------------------+---------------------------------------+
684-
| gregorian | ``cftime.DatetimeGregorian`` |
684+
| proleptic_gregorian | ``cftime.DatetimeProlepticGregorian`` |
685685
+--------------------------------+---------------------------------------+
686686
| noleap, 365_day | ``cftime.DatetimeNoLeap`` |
687687
+--------------------------------+---------------------------------------+

xarray/tests/test_cftime_offsets.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,3 +814,9 @@ def test_dayofyear_after_cftime_range(freq):
814814
result = cftime_range('2000-02-01', periods=3, freq=freq).dayofyear
815815
expected = pd.date_range('2000-02-01', periods=3, freq=freq).dayofyear
816816
np.testing.assert_array_equal(result, expected)
817+
818+
819+
def test_cftime_range_standard_calendar_refers_to_gregorian():
820+
from cftime import DatetimeGregorian
821+
result, = cftime_range('2000', periods=1)
822+
assert isinstance(result, DatetimeGregorian)

xarray/tests/test_interp.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,8 @@ def test_cftime_type_error():
523523
def test_cftime_list_of_strings():
524524
from cftime import DatetimeProlepticGregorian
525525

526-
times = xr.cftime_range('2000', periods=24, freq='D')
526+
times = xr.cftime_range('2000', periods=24, freq='D',
527+
calendar='proleptic_gregorian')
527528
da = xr.DataArray(np.arange(24), coords=[times], dims='time')
528529

529530
times_new = ['2000-01-01T12:00', '2000-01-02T12:00', '2000-01-03T12:00']
@@ -542,7 +543,8 @@ def test_cftime_list_of_strings():
542543
def test_cftime_single_string():
543544
from cftime import DatetimeProlepticGregorian
544545

545-
times = xr.cftime_range('2000', periods=24, freq='D')
546+
times = xr.cftime_range('2000', periods=24, freq='D',
547+
calendar='proleptic_gregorian')
546548
da = xr.DataArray(np.arange(24), coords=[times], dims='time')
547549

548550
times_new = '2000-01-01T12:00'

0 commit comments

Comments
 (0)