Skip to content

Commit 5ea1e81

Browse files
Maddogghoekmax-sixtykmuehlbauerspencerkclarkmaddogghoek
authored
deprecate cftime_range() in favor of date_range(use_cftime=True) (#10024)
Co-authored-by: Maximilian Roos <[email protected]> Co-authored-by: Kai Mühlbauer <[email protected]> Co-authored-by: Spencer Clark <[email protected]> Co-authored-by: maddogghoek <maddogghoek@penguin> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 2475d49 commit 5ea1e81

23 files changed

+467
-204
lines changed

Diff for: doc/contributing.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,9 @@ a user passes ``old_arg``, we would instead catch it:
580580
581581
def func(new_arg, old_arg=None):
582582
if old_arg is not None:
583-
from warnings import warn
583+
from xarray.core.utils import emit_user_level_warning
584584
585-
warn(
585+
emit_user_level_warning(
586586
"`old_arg` has been deprecated, and in the future will raise an error."
587587
"Please use `new_arg` from now on.",
588588
DeprecationWarning,

Diff for: doc/user-guide/weather-climate.rst

+11-4
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,18 @@ coordinate with dates from a no-leap calendar and a
9898
]
9999
da = xr.DataArray(np.arange(24), coords=[dates], dims=["time"], name="foo")
100100
101-
Xarray also includes a :py:func:`~xarray.cftime_range` function, which enables
101+
Xarray also includes a :py:func:`~xarray.date_range` function, which enables
102102
creating a :py:class:`~xarray.CFTimeIndex` with regularly-spaced dates. For
103-
instance, we can create the same dates and DataArray we created above using:
103+
instance, we can create the same dates and DataArray we created above using
104+
(note that ``use_cftime=True`` is not mandatory to return a
105+
:py:class:`~xarray.CFTimeIndex` for non-standard calendars, but can be nice
106+
to use to be explicit):
104107

105108
.. ipython:: python
106109
107-
dates = xr.cftime_range(start="0001", periods=24, freq="MS", calendar="noleap")
110+
dates = xr.date_range(
111+
start="0001", periods=24, freq="MS", calendar="noleap", use_cftime=True
112+
)
108113
da = xr.DataArray(np.arange(24), coords=[dates], dims=["time"], name="foo")
109114
110115
Mirroring pandas' method with the same name, :py:meth:`~xarray.infer_freq` allows one to
@@ -138,7 +143,9 @@ use ``pandas`` when possible, i.e. when the calendar is ``standard``/``gregorian
138143

139144
.. ipython:: python
140145
141-
dates = xr.cftime_range(start="2001", periods=24, freq="MS", calendar="noleap")
146+
dates = xr.date_range(
147+
start="2001", periods=24, freq="MS", calendar="noleap", use_cftime=True
148+
)
142149
da_nl = xr.DataArray(np.arange(24), coords=[dates], dims=["time"], name="foo")
143150
da_std = da.convert_calendar("standard", use_cftime=True)
144151

Diff for: doc/whats-new.rst

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Breaking changes
3838

3939
Deprecations
4040
~~~~~~~~~~~~
41+
- Deprecate :py:func:`~xarray.cftime_range` in favor of :py:func:`~xarray.date_range` with ``use_cftime=True``
42+
(:issue:`9886`, :pull:`10024`).
43+
By `Josh Kihm <https://github.com/maddogghoek>`_.
4144
- Move from phony_dims=None to phony_dims="access" for h5netcdf-backend(:issue:`10049`, :pull:`10058`)
4245
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
4346

0 commit comments

Comments
 (0)