From 1f813389d4b76354c8566d6759382e24cee91a0a Mon Sep 17 00:00:00 2001 From: keewis Date: Wed, 16 Oct 2019 20:54:27 +0200 Subject: [PATCH] Fixes to the resample docs (#3400) * add a missing newline to make sphinx detect the code block * update the link to the pandas documentation * explicitly state that this only works with datetime dimensions * also put the datetime dim requirement into the function description * add Series.resample and DataFrame.resample as reference * add the changes to whats-new.rst * move references to the bottom of the docstring --- doc/whats-new.rst | 7 +++++++ xarray/core/common.py | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 9e14120aeb3..2202c91408b 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -18,6 +18,13 @@ What's New v0.14.1 (unreleased) -------------------- +Documentation +~~~~~~~~~~~~~ + +- Fix the documentation of :py:meth:`DataArray.resample` and + :py:meth:`Dataset.resample` and explicitly state that a + datetime-like dimension is required. (:pull:`3400`) + By `Justus Magin `_. .. _whats-new.0.14.0: diff --git a/xarray/core/common.py b/xarray/core/common.py index 8313247c743..a762f7fbed9 100644 --- a/xarray/core/common.py +++ b/xarray/core/common.py @@ -914,13 +914,16 @@ def resample( ): """Returns a Resample object for performing resampling operations. - Handles both downsampling and upsampling. If any intervals contain no - values from the original object, they will be given the value ``NaN``. + Handles both downsampling and upsampling. The resampled + dimension must be a datetime-like coordinate. If any intervals + contain no values from the original object, they will be given + the value ``NaN``. Parameters ---------- indexer : {dim: freq}, optional - Mapping from the dimension name to resample frequency. + Mapping from the dimension name to resample frequency. The + dimension must be datetime-like. skipna : bool, optional Whether to skip missing values when aggregating in downsampling. closed : 'left' or 'right', optional @@ -978,12 +981,18 @@ def resample( * time (time) datetime64[ns] 1999-12-15 1999-12-16 1999-12-17 ... Limit scope of upsampling method + >>> da.resample(time='1D').nearest(tolerance='1D') array([ 0., 0., nan, ..., nan, 11., 11.]) Coordinates: * time (time) datetime64[ns] 1999-12-15 1999-12-16 ... 2000-11-15 + See Also + -------- + pandas.Series.resample + pandas.DataFrame.resample + References ----------