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 certain cftime frequency strings following pandas #8415

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions doc/user-guide/time-series.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ items and with the `slice` object:

.. ipython:: python
time = pd.date_range("2000-01-01", freq="H", periods=365 * 24)
time = pd.date_range("2000-01-01", freq="h", periods=365 * 24)
ds = xr.Dataset({"foo": ("time", np.arange(365 * 24)), "time": time})
ds.sel(time="2000-01")
ds.sel(time=slice("2000-06-01", "2000-06-10"))
Expand All @@ -115,7 +115,7 @@ given ``DataArray`` can be quickly computed using a special ``.dt`` accessor.

.. ipython:: python
time = pd.date_range("2000-01-01", freq="6H", periods=365 * 4)
time = pd.date_range("2000-01-01", freq="6h", periods=365 * 4)
ds = xr.Dataset({"foo": ("time", np.arange(365 * 4)), "time": time})
ds.time.dt.hour
ds.time.dt.dayofweek
Expand Down Expand Up @@ -207,7 +207,7 @@ For example, we can downsample our dataset from hourly to 6-hourly:
.. ipython:: python
:okwarning:
ds.resample(time="6H")
ds.resample(time="6h")
This will create a specialized ``Resample`` object which saves information
necessary for resampling. All of the reduction methods which work with
Expand All @@ -216,21 +216,21 @@ necessary for resampling. All of the reduction methods which work with
.. ipython:: python
:okwarning:
ds.resample(time="6H").mean()
ds.resample(time="6h").mean()
You can also supply an arbitrary reduction function to aggregate over each
resampling group:

.. ipython:: python
ds.resample(time="6H").reduce(np.mean)
ds.resample(time="6h").reduce(np.mean)
You can also resample on the time dimension while applying reducing along other dimensions at the same time
by specifying the `dim` keyword argument

.. code-block:: python
ds.resample(time="6H").mean(dim=["time", "latitude", "longitude"])
ds.resample(time="6h").mean(dim=["time", "latitude", "longitude"])
For upsampling, xarray provides six methods: ``asfreq``, ``ffill``, ``bfill``, ``pad``,
``nearest`` and ``interpolate``. ``interpolate`` extends ``scipy.interpolate.interp1d``
Expand All @@ -243,7 +243,7 @@ Data that has indices outside of the given ``tolerance`` are set to ``NaN``.

.. ipython:: python
ds.resample(time="1H").nearest(tolerance="1H")
ds.resample(time="1h").nearest(tolerance="1h")
For more examples of using grouped operations on a time dimension, see
Expand Down
2 changes: 1 addition & 1 deletion doc/user-guide/weather-climate.rst
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ For data indexed by a :py:class:`~xarray.CFTimeIndex` xarray currently supports:

.. ipython:: python
da.resample(time="81T", closed="right", label="right", offset="3T").mean()
da.resample(time="81min", closed="right", label="right", offset="3min").mean()
.. _nanosecond-precision range: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#timestamp-limitations
.. _ISO 8601 standard: https://en.wikipedia.org/wiki/ISO_8601
Expand Down
14 changes: 14 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ New Features
Breaking changes
~~~~~~~~~~~~~~~~

- Following pandas, :py:meth:`infer_freq` will return ``"Y"``, ``"YS"``,
``"QE"``, ``"ME"``, ``"h"``, ``"min"``, ``"s"``, ``"ms"``, ``"us"``, or
``"ns"`` instead of ``"A"``, ``"AS"``, ``"Q"``, ``"M"``, ``"H"``, ``"T"``,
``"S"``, ``"L"``, ``"U"``, or ``"N"``. This is to be consistent with the
deprecation of the latter frequency strings (:issue:`8394`, :pull:`8415`). By
`Spencer Clark <https://github.com/spencerkclark>`_.

Deprecations
~~~~~~~~~~~~
Expand All @@ -39,6 +45,14 @@ Deprecations
this was one place in the API where dimension positions were used.
(:pull:`8341`)
By `Maximilian Roos <https://github.com/max-sixty>`_.
- Following pandas, the frequency strings ``"A"``, ``"AS"``, ``"Q"``, ``"M"``,
``"H"``, ``"T"``, ``"S"``, ``"L"``, ``"U"``, and ``"N"`` are deprecated in
favor of ``"Y"``, ``"YS"``, ``"QE"``, ``"ME"``, ``"h"``, ``"min"``, ``"s"``,
``"ms"``, ``"us"``, and ``"ns"``, respectively. These strings are used, for
example, in :py:func:`date_range`, :py:func:`cftime_range`,
:py:meth:`DataArray.resample`, and :py:meth:`Dataset.resample` among others
(:issue:`8394`, :pull:`8415`). By `Spencer Clark
<https://github.com/spencerkclark>`_.

Bug fixes
~~~~~~~~~
Expand Down
Loading
Loading