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

Use DatetimeGregorian when calendar='standard' in cftime_range instead of DatetimeProlepticGregorian #2771

Merged
merged 1 commit into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ Bug fixes
- Masking data arrays with :py:meth:`xarray.DataArray.where` now returns an
array with the name of the original masked array (:issue:`2748` and :issue:`2457`).
By `Yohai Bar-Sinai <https://github.com/yohai>`_.
- Per `CF conventions
<http://cfconventions.org/cf-conventions/cf-conventions.html#calendar>`_,
specifying ``'standard'`` as the calendar type in
:py:meth:`~xarray.cftime_range` now correctly refers to the ``'gregorian'``
calendar instead of the ``'proleptic_gregorian'`` calendar (:issue:`2761`).

.. _whats-new.0.11.3:

v0.11.3 (26 January 2019)
Expand Down
6 changes: 3 additions & 3 deletions xarray/coding/cftime_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_date_type(calendar):
'proleptic_gregorian': cftime.DatetimeProlepticGregorian,
'julian': cftime.DatetimeJulian,
'all_leap': cftime.DatetimeAllLeap,
'standard': cftime.DatetimeProlepticGregorian
'standard': cftime.DatetimeGregorian
}
return calendars[calendar]

Expand Down Expand Up @@ -679,9 +679,9 @@ def cftime_range(start=None, end=None, periods=None, freq='D',
+--------------------------------+---------------------------------------+
| Alias | Date type |
+================================+=======================================+
| standard, proleptic_gregorian | ``cftime.DatetimeProlepticGregorian`` |
| standard, gregorian | ``cftime.DatetimeGregorian`` |
+--------------------------------+---------------------------------------+
| gregorian | ``cftime.DatetimeGregorian`` |
| proleptic_gregorian | ``cftime.DatetimeProlepticGregorian`` |
+--------------------------------+---------------------------------------+
| noleap, 365_day | ``cftime.DatetimeNoLeap`` |
+--------------------------------+---------------------------------------+
Expand Down
6 changes: 6 additions & 0 deletions xarray/tests/test_cftime_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,3 +814,9 @@ def test_dayofyear_after_cftime_range(freq):
result = cftime_range('2000-02-01', periods=3, freq=freq).dayofyear
expected = pd.date_range('2000-02-01', periods=3, freq=freq).dayofyear
np.testing.assert_array_equal(result, expected)


def test_cftime_range_standard_calendar_refers_to_gregorian():
from cftime import DatetimeGregorian
result, = cftime_range('2000', periods=1)
assert isinstance(result, DatetimeGregorian)
6 changes: 4 additions & 2 deletions xarray/tests/test_interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,8 @@ def test_cftime_type_error():
def test_cftime_list_of_strings():
from cftime import DatetimeProlepticGregorian

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

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

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

times_new = '2000-01-01T12:00'
Expand Down