Skip to content

Commit 52866a8

Browse files
committed
Note that use_cftime is only relevant for standard calendar dates
1 parent 71679c0 commit 52866a8

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

doc/whats-new.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ Enhancements
7070
(:issue:`2688`). By `Spencer Clark <https://github.com/spencerkclark>`_.
7171
- :py:meth:`~xarray.open_dataset` now accepts a ``use_cftime`` argument, which
7272
can be used to require that ``cftime.datetime`` objects are always used, or
73-
never used when decoding dates. This can be used to ensure consistent date
74-
types are returned when using :py:meth:`~xarray.open_mfdataset`
75-
(:issue:`1263`) and/or to silence serialization warnings raised if dates from
76-
a standard calendar are found to be outside the
77-
:py:class:`pandas.Timestamp`-valid range (:issue:`2754`). By `Spencer Clark
78-
<https://github.com/spencerkclark>`_.
73+
never used when decoding dates encoded with a standard calendar. This can be
74+
used to ensure consistent date types are returned when using
75+
:py:meth:`~xarray.open_mfdataset` (:issue:`1263`) and/or to silence
76+
serialization warnings raised if dates from a standard calendar are found to
77+
be outside the :py:class:`pandas.Timestamp`-valid range (:issue:`2754`). By
78+
`Spencer Clark <https://github.com/spencerkclark>`_.
7979

8080
Bug fixes
8181
~~~~~~~~~

xarray/backends/api.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,15 @@ def open_dataset(filename_or_obj, group=None, decode_cf=True,
232232
may be useful when backend options would improve performance or
233233
allow user control of dataset processing.
234234
use_cftime: bool, optional
235-
If None (default), attempt to decode times to ``np.datetime64[ns]``
236-
objects; if this is not possible, decode times to ``cftime.datetime``
237-
objects. If True, always decode times to ``cftime.datetime`` objects,
238-
regardless of whether or not they can be represented using
239-
``np.datetime64[ns]`` objects. If False, always decode times to
240-
``np.datetime64[ns]`` objects; if this is not possible raise an error.
235+
Only relevant if encoded dates come from a standard calendar
236+
(e.g. 'gregorian', 'proleptic_gregorian', 'standard', or not
237+
specified). If None (default), attempt to decode times to
238+
``np.datetime64[ns]`` objects; if this is not possible, decode times to
239+
``cftime.datetime`` objects. If True, always decode times to
240+
``cftime.datetime`` objects, regardless of whether or not they can be
241+
represented using ``np.datetime64[ns]`` objects. If False, always
242+
decode times to ``np.datetime64[ns]`` objects; if this is not possible
243+
raise an error.
241244
242245
Returns
243246
-------
@@ -437,12 +440,15 @@ def open_dataarray(filename_or_obj, group=None, decode_cf=True,
437440
may be useful when backend options would improve performance or
438441
allow user control of dataset processing.
439442
use_cftime: bool, optional
440-
If None (default), attempt to decode times to ``np.datetime64[ns]``
441-
objects; if this is not possible, decode times to ``cftime.datetime``
442-
objects. If True, always decode times to ``cftime.datetime`` objects,
443-
regardless of whether or not they can be represented using
444-
``np.datetime64[ns]`` objects. If False, always decode times to
445-
``np.datetime64[ns]`` objects; if this is not possible raise an error.
443+
Only relevant if encoded dates come from a standard calendar
444+
(e.g. 'gregorian', 'proleptic_gregorian', 'standard', or not
445+
specified). If None (default), attempt to decode times to
446+
``np.datetime64[ns]`` objects; if this is not possible, decode times to
447+
``cftime.datetime`` objects. If True, always decode times to
448+
``cftime.datetime`` objects, regardless of whether or not they can be
449+
represented using ``np.datetime64[ns]`` objects. If False, always
450+
decode times to ``np.datetime64[ns]`` objects; if this is not possible
451+
raise an error.
446452
447453
Notes
448454
-----

xarray/conventions.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,15 @@ def decode_cf_variable(name, var, concat_characters=True, mask_and_scale=True,
271271
array. Passed as an argument because we need to look at the full
272272
dataset to figure out if this is appropriate.
273273
use_cftime: bool, optional
274-
If None (default), attempt to decode times to ``np.datetime64[ns]``
275-
objects; if this is not possible, decode times to ``cftime.datetime``
276-
objects. If True, always decode times to ``cftime.datetime`` objects,
277-
regardless of whether or not they can be represented using
278-
``np.datetime64[ns]`` objects. If False, always decode times to
279-
``np.datetime64[ns]`` objects; if this is not possible raise an error.
274+
Only relevant if encoded dates come from a standard calendar
275+
(e.g. 'gregorian', 'proleptic_gregorian', 'standard', or not
276+
specified). If None (default), attempt to decode times to
277+
``np.datetime64[ns]`` objects; if this is not possible, decode times to
278+
``cftime.datetime`` objects. If True, always decode times to
279+
``cftime.datetime`` objects, regardless of whether or not they can be
280+
represented using ``np.datetime64[ns]`` objects. If False, always
281+
decode times to ``np.datetime64[ns]`` objects; if this is not possible
282+
raise an error.
280283
281284
Returns
282285
-------
@@ -441,12 +444,15 @@ def decode_cf(obj, concat_characters=True, mask_and_scale=True,
441444
dataset. This may be useful to drop variables with problems or
442445
inconsistent values.
443446
use_cftime: bool, optional
444-
If None (default), attempt to decode times to ``np.datetime64[ns]``
445-
objects; if this is not possible, decode times to ``cftime.datetime``
446-
objects. If True, always decode times to ``cftime.datetime`` objects,
447-
regardless of whether or not they can be represented using
448-
``np.datetime64[ns]`` objects. If False, always decode times to
449-
``np.datetime64[ns]`` objects; if this is not possible raise an error.
447+
Only relevant if encoded dates come from a standard calendar
448+
(e.g. 'gregorian', 'proleptic_gregorian', 'standard', or not
449+
specified). If None (default), attempt to decode times to
450+
``np.datetime64[ns]`` objects; if this is not possible, decode times to
451+
``cftime.datetime`` objects. If True, always decode times to
452+
``cftime.datetime`` objects, regardless of whether or not they can be
453+
represented using ``np.datetime64[ns]`` objects. If False, always
454+
decode times to ``np.datetime64[ns]`` objects; if this is not possible
455+
raise an error.
450456
451457
Returns
452458
-------

0 commit comments

Comments
 (0)