Skip to content

Commit 12e4b59

Browse files
committed
Deprecate certain frequency strings following pandas [test-upstream]
Specifically 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.
1 parent 83fbcf0 commit 12e4b59

18 files changed

+433
-319
lines changed

doc/user-guide/time-series.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ items and with the `slice` object:
8989

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

116116
.. ipython:: python
117117
118-
time = pd.date_range("2000-01-01", freq="6H", periods=365 * 4)
118+
time = pd.date_range("2000-01-01", freq="6h", periods=365 * 4)
119119
ds = xr.Dataset({"foo": ("time", np.arange(365 * 4)), "time": time})
120120
ds.time.dt.hour
121121
ds.time.dt.dayofweek
@@ -207,7 +207,7 @@ For example, we can downsample our dataset from hourly to 6-hourly:
207207
.. ipython:: python
208208
:okwarning:
209209
210-
ds.resample(time="6H")
210+
ds.resample(time="6h")
211211
212212
This will create a specialized ``Resample`` object which saves information
213213
necessary for resampling. All of the reduction methods which work with
@@ -216,21 +216,21 @@ necessary for resampling. All of the reduction methods which work with
216216
.. ipython:: python
217217
:okwarning:
218218
219-
ds.resample(time="6H").mean()
219+
ds.resample(time="6h").mean()
220220
221221
You can also supply an arbitrary reduction function to aggregate over each
222222
resampling group:
223223

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

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

244244
.. ipython:: python
245245
246-
ds.resample(time="1H").nearest(tolerance="1H")
246+
ds.resample(time="1h").nearest(tolerance="1h")
247247
248248
249249
For more examples of using grouped operations on a time dimension, see

doc/user-guide/weather-climate.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ For data indexed by a :py:class:`~xarray.CFTimeIndex` xarray currently supports:
239239

240240
.. ipython:: python
241241
242-
da.resample(time="81T", closed="right", label="right", offset="3T").mean()
242+
da.resample(time="81min", closed="right", label="right", offset="3min").mean()
243243
244244
.. _nanosecond-precision range: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#timestamp-limitations
245245
.. _ISO 8601 standard: https://en.wikipedia.org/wiki/ISO_8601

doc/whats-new.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ New Features
2828
Breaking changes
2929
~~~~~~~~~~~~~~~~
3030

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

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

4357
Bug fixes
4458
~~~~~~~~~

0 commit comments

Comments
 (0)