@@ -74,7 +74,7 @@ will be used for indexing. :py:class:`~xarray.CFTimeIndex` enables a subset of
7474the indexing functionality of a :py:class: `pandas.DatetimeIndex ` and is only
7575fully compatible with the standalone version of ``cftime `` (not the version
7676packaged with earlier versions ``netCDF4 ``). See :ref: `CFTimeIndex ` for more
77- information.
77+ information.
7878
7979Datetime indexing
8080-----------------
@@ -215,7 +215,7 @@ For more examples of using grouped operations on a time dimension, see
215215
216216
217217.. _CFTimeIndex :
218-
218+
219219Non-standard calendars and dates outside the Timestamp-valid range
220220------------------------------------------------------------------
221221
@@ -224,14 +224,14 @@ Through the standalone ``cftime`` library and a custom subclass of
224224functionality enabled through the standard :py:class: `pandas.DatetimeIndex ` for
225225dates from non-standard calendars commonly used in climate science or dates
226226using a standard calendar, but outside the `Timestamp-valid range `_
227- (approximately between years 1678 and 2262).
227+ (approximately between years 1678 and 2262).
228228
229229.. note ::
230230
231231 As of xarray version 0.11, by default, :py:class: `cftime.datetime ` objects
232232 will be used to represent times (either in indexes, as a
233- :py:class: `~xarray.CFTimeIndex `, or in data arrays with dtype object) if
234- any of the following are true:
233+ :py:class: `~xarray.CFTimeIndex `, or in data arrays with dtype object) if
234+ any of the following are true:
235235
236236 - The dates are from a non-standard calendar
237237 - Any dates are outside the Timestamp-valid range.
@@ -252,7 +252,7 @@ coordinate with dates from a no-leap calendar and a
252252 dates = [DatetimeNoLeap(year, month, 1 ) for year, month in
253253 product(range (1 , 3 ), range (1 , 13 ))]
254254 da = xr.DataArray(np.arange(24 ), coords = [dates], dims = [' time' ], name = ' foo' )
255-
255+
256256 xarray also includes a :py:func: `~xarray.cftime_range ` function, which enables
257257creating a :py:class: `~xarray.CFTimeIndex ` with regularly-spaced dates. For
258258instance, we can create the same dates and DataArray we created above using:
@@ -261,20 +261,20 @@ instance, we can create the same dates and DataArray we created above using:
261261
262262 dates = xr.cftime_range(start = ' 0001' , periods = 24 , freq = ' MS' , calendar = ' noleap' )
263263 da = xr.DataArray(np.arange(24 ), coords = [dates], dims = [' time' ], name = ' foo' )
264-
264+
265265 For data indexed by a :py:class: `~xarray.CFTimeIndex ` xarray currently supports:
266266
267267- `Partial datetime string indexing `_ using strictly `ISO 8601-format `_ partial
268268 datetime strings:
269-
269+
270270.. ipython :: python
271271
272272 da.sel(time = ' 0001' )
273273 da.sel(time = slice (' 0001-05' , ' 0002-02' ))
274274
275275 - Access of basic datetime components via the ``dt `` accessor (in this case
276276 just "year", "month", "day", "hour", "minute", "second", "microsecond",
277- "season", "dayofyear", and "dayofweek"):
277+ "season", "dayofyear", and "dayofweek"):
278278
279279.. ipython :: python
280280
@@ -309,31 +309,27 @@ For data indexed by a :py:class:`~xarray.CFTimeIndex` xarray currently supports:
309309
310310 da.differentiate(' time' )
311311
312- - And serialization :
312+ - Serialization :
313313
314314.. ipython :: python
315315
316316 da.to_netcdf(' example-no-leap.nc' )
317317 xr.open_dataset(' example-no-leap.nc' )
318318
319- .. note ::
320-
321- While much of the time series functionality that is possible for standard
322- dates has been implemented for dates from non-standard calendars, there are
323- still some remaining important features that have yet to be implemented,
324- for example:
319+ - And resampling along the time dimension for data indexed by a :py:class: `~xarray.CFTimeIndex `:
325320
326- - Resampling along the time dimension for data indexed by a
327- :py:class: `~xarray.CFTimeIndex ` (:issue: `2191 `, :issue: `2458 `)
328- - Built-in plotting of data with :py:class: `cftime.datetime ` coordinate axes
329- (:issue: `2164 `).
321+ .. ipython :: python
322+
323+ da.resample(time = ' 81T' , closed = ' right' , label = ' right' , base = 3 ).mean()
324+
325+ .. note ::
326+
330327
331328 For some use-cases it may still be useful to convert from
332329 a :py:class: `~xarray.CFTimeIndex ` to a :py:class: `pandas.DatetimeIndex `,
333- despite the difference in calendar types (e.g. to allow the use of some
334- forms of resample with non-standard calendars). The recommended way of
335- doing this is to use the built-in
336- :py:meth: `~xarray.CFTimeIndex.to_datetimeindex ` method:
330+ despite the difference in calendar types. The recommended way of doing this
331+ is to use the built-in :py:meth: `~xarray.CFTimeIndex.to_datetimeindex `
332+ method:
337333
338334 .. ipython :: python
339335 :okwarning:
@@ -343,14 +339,13 @@ For data indexed by a :py:class:`~xarray.CFTimeIndex` xarray currently supports:
343339 da
344340 datetimeindex = da.indexes[' time' ].to_datetimeindex()
345341 da[' time' ] = datetimeindex
346- da.resample(time = ' Y' ).mean(' time' )
347-
342+
348343 However in this case one should use caution to only perform operations which
349344 do not depend on differences between dates (e.g. differentiation,
350345 interpolation, or upsampling with resample), as these could introduce subtle
351346 and silent errors due to the difference in calendar types between the dates
352- encoded in your data and the dates stored in memory.
353-
347+ encoded in your data and the dates stored in memory.
348+
354349.. _Timestamp-valid range : https://pandas.pydata.org/pandas-docs/stable/timeseries.html#timestamp-limitations
355350.. _ISO 8601-format : https://en.wikipedia.org/wiki/ISO_8601
356351.. _partial datetime string indexing : https://pandas.pydata.org/pandas-docs/stable/timeseries.html#partial-string-indexing
0 commit comments