Skip to content

Commit 392c092

Browse files
author
maddogghoek
committed
- Update cftime_range example to expect deprecation warning.
- update other examples that call cftime_range to use date_range(use_cftime=True) instead Issue pydata#9886
1 parent 87f0cde commit 392c092

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

xarray/coding/cftime_offsets.py

+3
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,9 @@ def cftime_range(
11131113
objects associated with the specified calendar type, e.g.
11141114
11151115
>>> xr.cftime_range(start="2000", periods=6, freq="2MS", calendar="noleap")
1116+
Traceback (most recent call last):
1117+
...
1118+
DeprecationWarning: cftime_range() is deprecated, please use date_range(use_cftime=True) instead.
11161119
CFTimeIndex([2000-01-01 00:00:00, 2000-03-01 00:00:00, 2000-05-01 00:00:00,
11171120
2000-07-01 00:00:00, 2000-09-01 00:00:00, 2000-11-01 00:00:00],
11181121
dtype='object', length=6, calendar='noleap', freq='2MS')

xarray/coding/cftimeindex.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ class CFTimeIndex(pd.Index):
236236
237237
See Also
238238
--------
239-
cftime_range
239+
date_range
240240
"""
241241

242242
_data: np.ndarray
@@ -463,7 +463,7 @@ def shift( # type: ignore[override] # freq is typed Any, we are more precise
463463
) -> Self:
464464
"""Shift the CFTimeIndex a multiple of the given frequency.
465465
466-
See the documentation for :py:func:`~xarray.cftime_range` for a
466+
See the documentation for :py:func:`~xarray.date_range` for a
467467
complete listing of valid frequency strings.
468468
469469
Parameters
@@ -483,7 +483,7 @@ def shift( # type: ignore[override] # freq is typed Any, we are more precise
483483
484484
Examples
485485
--------
486-
>>> index = xr.cftime_range("2000", periods=1, freq="ME")
486+
>>> index = xr.date_range("2000", periods=1, freq="ME", use_cftime=True)
487487
>>> index
488488
CFTimeIndex([2000-01-31 00:00:00],
489489
dtype='object', length=1, calendar='standard', freq=None)
@@ -586,7 +586,9 @@ def to_datetimeindex(
586586
587587
Examples
588588
--------
589-
>>> times = xr.cftime_range("2000", periods=2, calendar="gregorian")
589+
>>> times = xr.date_range(
590+
... "2000", periods=2, calendar="gregorian", use_cftime=True
591+
... )
590592
>>> times
591593
CFTimeIndex([2000-01-01 00:00:00, 2000-01-02 00:00:00],
592594
dtype='object', length=2, calendar='standard', freq=None)
@@ -652,8 +654,12 @@ def strftime(self, date_format):
652654
653655
Examples
654656
--------
655-
>>> rng = xr.cftime_range(
656-
... start="2000", periods=5, freq="2MS", calendar="noleap"
657+
>>> rng = xr.date_range(
658+
... start="2000",
659+
... periods=5,
660+
... freq="2MS",
661+
... calendar="noleap",
662+
... use_cftime=True,
657663
... )
658664
>>> rng.strftime("%B %d, %Y, %r")
659665
Index(['January 01, 2000, 12:00:00 AM', 'March 01, 2000, 12:00:00 AM',

xarray/core/dataarray.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5618,7 +5618,7 @@ def map_blocks(
56185618
... clim = gb.mean(dim="time")
56195619
... return gb - clim
56205620
...
5621-
>>> time = xr.cftime_range("1990-01", "1992-01", freq="ME")
5621+
>>> time = xr.date_range("1990-01", "1992-01", freq="ME", use_cftime=True)
56225622
>>> month = xr.DataArray(time.month, coords={"time": time}, dims=["time"])
56235623
>>> np.random.seed(123)
56245624
>>> array = xr.DataArray(

xarray/core/dataset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9024,7 +9024,7 @@ def map_blocks(
90249024
... clim = gb.mean(dim="time")
90259025
... return gb - clim
90269026
...
9027-
>>> time = xr.cftime_range("1990-01", "1992-01", freq="ME")
9027+
>>> time = xr.date_range("1990-01", "1992-01", freq="ME", use_cftime=True)
90289028
>>> month = xr.DataArray(time.month, coords={"time": time}, dims=["time"])
90299029
>>> np.random.seed(123)
90309030
>>> array = xr.DataArray(

xarray/core/parallel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def map_blocks(
296296
... clim = gb.mean(dim="time")
297297
... return gb - clim
298298
...
299-
>>> time = xr.cftime_range("1990-01", "1992-01", freq="ME")
299+
>>> time = xr.date_range("1990-01", "1992-01", freq="ME", use_cftime=True)
300300
>>> month = xr.DataArray(time.month, coords={"time": time}, dims=["time"])
301301
>>> np.random.seed(123)
302302
>>> array = xr.DataArray(

0 commit comments

Comments
 (0)