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

deprecate cftime_range() in favor of date_range(use_cftime=True) #10024

Merged
merged 47 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
fc954de
Deprecate cftime_range() and some refactoring
Feb 4, 2025
7affcc6
updated whats-new.rst
Feb 4, 2025
87f0cde
Add deprecation warning to cftime_range()
Feb 4, 2025
635aa2c
Merge branch 'main' into cftime_deprecation
Maddogghoek Feb 4, 2025
392c092
- Update cftime_range example to expect deprecation warning.
Feb 7, 2025
f6677eb
Merge branch 'cftime_deprecation' of https://github.com/maddogghoek/x…
Feb 7, 2025
5b162fc
Merge branch 'main' into cftime_deprecation
Maddogghoek Feb 7, 2025
dec7df5
Update whats-new.rst
Maddogghoek Feb 7, 2025
003edc8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 7, 2025
a072f1b
always import core.types.InclusionOptions
Feb 7, 2025
e0cfdaa
Merge branch 'cftime_deprecation' of https://github.com/maddogghoek/x…
Feb 7, 2025
9bf05e2
fix check of InclusiveOptions Literal check
Feb 7, 2025
49a249f
remove dead code
Feb 7, 2025
62df181
- Replace calls to cftime_range in core and unit tests
Feb 7, 2025
7938bb7
ignore deprecation warnings in test_cftime_offsets.py
Feb 7, 2025
7fbff45
- Update cftime_range doctest to ignore deprecation warning.
Feb 7, 2025
7324f25
- Fix test_cftime_or_date_range_invalid_inclusive_value for cases where
Feb 7, 2025
da4d9f5
update weather-climate.rst to use date_range rather than deprecated c…
Feb 7, 2025
d500e79
only check inclusive argument when not already type checked to avoid …
Feb 7, 2025
9b45bc8
skip invalid inclusion value if type checking is turned on
Feb 8, 2025
f68277e
remove unneeded ignore arg type comments
Feb 8, 2025
2fa10f6
s/Illegal/Invalid/ in error message for cftime_range
Maddogghoek Feb 11, 2025
7c4f77b
Merge branch 'main' into cftime_deprecation
Maddogghoek Feb 11, 2025
0e5ee06
Update doc/whats-new.rst
Maddogghoek Feb 14, 2025
7409c1b
remove accidentally included documenation artifact
Feb 14, 2025
882c53e
Merge branch 'main' into cftime_deprecation
Maddogghoek Feb 14, 2025
7765d91
update to use data_range instead of cftime_range
Maddogghoek Feb 18, 2025
eb87222
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 18, 2025
899f123
remove "bug fix" for #9886
Maddogghoek Feb 18, 2025
12a5c65
fix documentation typo
Maddogghoek Feb 18, 2025
6e7444a
update backwards compatibility section example to use xarray.core.uti…
Feb 18, 2025
3adf065
update cftime_range deprecation warning to use emit_user_level_warnin…
Feb 18, 2025
40222b8
add "linear" to internal generate_date_range* function names per code…
Feb 18, 2025
16ca397
clean up cftime_range docum
Maddogghoek Feb 18, 2025
0004584
replace deprecated cftime_range with date_range(use_cftime=True) for …
Feb 18, 2025
1076dab
Merge branch 'cftime_deprecation' of https://github.com/maddogghoek/x…
Feb 18, 2025
fec6a99
copy and update cftime_range() documentation notes to date_range() (#…
Feb 18, 2025
d611fbc
remove erroneous "stacklevel" argument from emit_user_level_warning c…
Feb 18, 2025
acfcaf7
fix test_invalid_date_range_cftime_inputs to catch expected exception…
Feb 19, 2025
a0acfd3
Merge branch 'main' into cftime_deprecation
Maddogghoek Feb 19, 2025
8bf8160
improve invalid input error message for date_range()
Maddogghoek Feb 21, 2025
773a7b2
reformat deprecation note
Maddogghoek Feb 21, 2025
3971ce0
Minor documentation improvement for date_range()
Maddogghoek Feb 21, 2025
8e43215
Fix date_range() documentation
Maddogghoek Feb 21, 2025
5043c85
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 21, 2025
4d75b40
remove long url from date_range() documentation
Maddogghoek Feb 21, 2025
9c70c6a
Merge branch 'main' into cftime_deprecation
Maddogghoek Feb 24, 2025
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
4 changes: 2 additions & 2 deletions doc/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,9 @@ a user passes ``old_arg``, we would instead catch it:
def func(new_arg, old_arg=None):
if old_arg is not None:
from warnings import warn
from xarray.core.utils import emit_user_level_warning
warn(
emit_user_level_warning(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for updating this in the contributing guide!

"`old_arg` has been deprecated, and in the future will raise an error."
"Please use `new_arg` from now on.",
DeprecationWarning,
Expand Down
15 changes: 11 additions & 4 deletions doc/user-guide/weather-climate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,18 @@ coordinate with dates from a no-leap calendar and a
]
da = xr.DataArray(np.arange(24), coords=[dates], dims=["time"], name="foo")

Xarray also includes a :py:func:`~xarray.cftime_range` function, which enables
Xarray also includes a :py:func:`~xarray.date_range` function, which enables
creating a :py:class:`~xarray.CFTimeIndex` with regularly-spaced dates. For
instance, we can create the same dates and DataArray we created above using:
instance, we can create the same dates and DataArray we created above using
(note that ``use_cftime=True`` is not mandatory to return a
:py:class:`~xarray.CFTimeIndex` for non-standard calendars, but can be nice
to use to be explicit):

.. ipython:: python

dates = xr.cftime_range(start="0001", periods=24, freq="MS", calendar="noleap")
dates = xr.date_range(
start="0001", periods=24, freq="MS", calendar="noleap", use_cftime=True
)
da = xr.DataArray(np.arange(24), coords=[dates], dims=["time"], name="foo")

Mirroring pandas' method with the same name, :py:meth:`~xarray.infer_freq` allows one to
Expand Down Expand Up @@ -138,7 +143,9 @@ use ``pandas`` when possible, i.e. when the calendar is ``standard``/``gregorian

.. ipython:: python

dates = xr.cftime_range(start="2001", periods=24, freq="MS", calendar="noleap")
dates = xr.date_range(
start="2001", periods=24, freq="MS", calendar="noleap", use_cftime=True
)
da_nl = xr.DataArray(np.arange(24), coords=[dates], dims=["time"], name="foo")
da_std = da.convert_calendar("standard", use_cftime=True)

Expand Down
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ Breaking changes

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

Expand Down
Loading
Loading