Skip to content
forked from pydata/xarray

Commit

Permalink
Merge branch 'main' into chunk-by-frequency
Browse files Browse the repository at this point in the history
* main:
  Delete ``base`` and ``loffset`` parameters to resample (pydata#9233)
  Update dropna docstring (pydata#9257)
  • Loading branch information
dcherian committed Jul 19, 2024
2 parents 5c39645 + 39d5b39 commit 5e61d14
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 402 deletions.
5 changes: 5 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ New Features

Breaking changes
~~~~~~~~~~~~~~~~
- The ``base`` and ``loffset`` parameters to :py:meth:`Dataset.resample` and :py:meth:`DataArray.resample`
is now removed. These parameters has been deprecated since v2023.03.0. Using the
``origin`` or ``offset`` parameters is recommended as a replacement for using
the ``base`` parameter and using time offset arithmetic is recommended as a
replacement for using the ``loffset`` parameter.


Deprecations
Expand Down
46 changes: 2 additions & 44 deletions xarray/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,10 +881,8 @@ def _resample(
skipna: bool | None,
closed: SideOptions | None,
label: SideOptions | None,
base: int | None,
offset: pd.Timedelta | datetime.timedelta | str | None,
origin: str | DatetimeLike,
loffset: datetime.timedelta | str | None,
restore_coord_dims: bool | None,
**indexer_kwargs: str | Resampler,
) -> T_Resample:
Expand All @@ -906,16 +904,6 @@ def _resample(
Side of each interval to treat as closed.
label : {"left", "right"}, optional
Side of each interval to use for labeling.
base : int, optional
For frequencies that evenly subdivide 1 day, the "origin" of the
aggregated intervals. For example, for "24H" frequency, base could
range from 0 through 23.
.. deprecated:: 2023.03.0
Following pandas, the ``base`` parameter is deprecated in favor
of the ``origin`` and ``offset`` parameters, and will be removed
in a future version of xarray.
origin : {'epoch', 'start', 'start_day', 'end', 'end_day'}, pd.Timestamp, datetime.datetime, np.datetime64, or cftime.datetime, default 'start_day'
The datetime on which to adjust the grouping. The timezone of origin
must match the timezone of the index.
Expand All @@ -928,15 +916,6 @@ def _resample(
- 'end_day': `origin` is the ceiling midnight of the last day
offset : pd.Timedelta, datetime.timedelta, or str, default is None
An offset timedelta added to the origin.
loffset : timedelta or str, optional
Offset used to adjust the resampled time labels. Some pandas date
offset strings are supported.
.. deprecated:: 2023.03.0
Following pandas, the ``loffset`` parameter is deprecated in favor
of using time offset arithmetic, and will be removed in a future
version of xarray.
restore_coord_dims : bool, optional
If True, also restore the dimension order of multi-dimensional
coordinates.
Expand Down Expand Up @@ -1072,18 +1051,6 @@ def _resample(
from xarray.core.groupers import Resampler, TimeResampler
from xarray.core.resample import RESAMPLE_DIM

# note: the second argument (now 'skipna') use to be 'dim'
if (
(skipna is not None and not isinstance(skipna, bool))
or ("how" in indexer_kwargs and "how" not in self.dims)
or ("dim" in indexer_kwargs and "dim" not in self.dims)
):
raise TypeError(
"resample() no longer supports the `how` or "
"`dim` arguments. Instead call methods on resample "
"objects, e.g., data.resample(time='1D').mean()"
)

indexer = either_dict_or_kwargs(indexer, indexer_kwargs, "resample")
if len(indexer) != 1:
raise ValueError("Resampling only supported along single dimensions.")
Expand All @@ -1093,22 +1060,13 @@ def _resample(
dim_coord = self[dim]

group = DataArray(
dim_coord,
coords=dim_coord.coords,
dims=dim_coord.dims,
name=RESAMPLE_DIM,
dim_coord, coords=dim_coord.coords, dims=dim_coord.dims, name=RESAMPLE_DIM
)

grouper: Resampler
if isinstance(freq, str):
grouper = TimeResampler(
freq=freq,
closed=closed,
label=label,
origin=origin,
offset=offset,
loffset=loffset,
base=base,
freq=freq, closed=closed, label=label, origin=origin, offset=offset
)
elif isinstance(freq, Resampler):
grouper = freq
Expand Down
17 changes: 0 additions & 17 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -7249,10 +7249,8 @@ def resample(
skipna: bool | None = None,
closed: SideOptions | None = None,
label: SideOptions | None = None,
base: int | None = None,
offset: pd.Timedelta | datetime.timedelta | str | None = None,
origin: str | DatetimeLike = "start_day",
loffset: datetime.timedelta | str | None = None,
restore_coord_dims: bool | None = None,
**indexer_kwargs: str | Resampler,
) -> DataArrayResample:
Expand All @@ -7274,10 +7272,6 @@ def resample(
Side of each interval to treat as closed.
label : {"left", "right"}, optional
Side of each interval to use for labeling.
base : int, optional
For frequencies that evenly subdivide 1 day, the "origin" of the
aggregated intervals. For example, for "24H" frequency, base could
range from 0 through 23.
origin : {'epoch', 'start', 'start_day', 'end', 'end_day'}, pd.Timestamp, datetime.datetime, np.datetime64, or cftime.datetime, default 'start_day'
The datetime on which to adjust the grouping. The timezone of origin
must match the timezone of the index.
Expand All @@ -7290,15 +7284,6 @@ def resample(
- 'end_day': `origin` is the ceiling midnight of the last day
offset : pd.Timedelta, datetime.timedelta, or str, default is None
An offset timedelta added to the origin.
loffset : timedelta or str, optional
Offset used to adjust the resampled time labels. Some pandas date
offset strings are supported.
.. deprecated:: 2023.03.0
Following pandas, the ``loffset`` parameter is deprecated in favor
of using time offset arithmetic, and will be removed in a future
version of xarray.
restore_coord_dims : bool, optional
If True, also restore the dimension order of multi-dimensional
coordinates.
Expand Down Expand Up @@ -7403,10 +7388,8 @@ def resample(
skipna=skipna,
closed=closed,
label=label,
base=base,
offset=offset,
origin=origin,
loffset=loffset,
restore_coord_dims=restore_coord_dims,
**indexer_kwargs,
)
Expand Down
30 changes: 9 additions & 21 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6412,7 +6412,7 @@ def dropna(
Data variables:
temperature (time, location) float64 64B 23.4 24.1 nan ... 24.2 20.5 25.3
# Drop NaN values from the dataset
Drop NaN values from the dataset
>>> dataset.dropna(dim="time")
<xarray.Dataset> Size: 80B
Expand All @@ -6423,7 +6423,7 @@ def dropna(
Data variables:
temperature (time, location) float64 48B 23.4 24.1 21.8 24.2 20.5 25.3
# Drop labels with any NAN values
Drop labels with any NaN values
>>> dataset.dropna(dim="time", how="any")
<xarray.Dataset> Size: 80B
Expand All @@ -6434,7 +6434,7 @@ def dropna(
Data variables:
temperature (time, location) float64 48B 23.4 24.1 21.8 24.2 20.5 25.3
# Drop labels with all NAN values
Drop labels with all NAN values
>>> dataset.dropna(dim="time", how="all")
<xarray.Dataset> Size: 104B
Expand All @@ -6445,7 +6445,7 @@ def dropna(
Data variables:
temperature (time, location) float64 64B 23.4 24.1 nan ... 24.2 20.5 25.3
# Drop labels with less than 2 non-NA values
Drop labels with less than 2 non-NA values
>>> dataset.dropna(dim="time", thresh=2)
<xarray.Dataset> Size: 80B
Expand All @@ -6459,6 +6459,11 @@ def dropna(
Returns
-------
Dataset
See Also
--------
DataArray.dropna
pandas.DataFrame.dropna
"""
# TODO: consider supporting multiple dimensions? Or not, given that
# there are some ugly edge cases, e.g., pandas's dropna differs
Expand Down Expand Up @@ -10667,10 +10672,8 @@ def resample(
skipna: bool | None = None,
closed: SideOptions | None = None,
label: SideOptions | None = None,
base: int | None = None,
offset: pd.Timedelta | datetime.timedelta | str | None = None,
origin: str | DatetimeLike = "start_day",
loffset: datetime.timedelta | str | None = None,
restore_coord_dims: bool | None = None,
**indexer_kwargs: str | Resampler,
) -> DatasetResample:
Expand All @@ -10692,10 +10695,6 @@ def resample(
Side of each interval to treat as closed.
label : {"left", "right"}, optional
Side of each interval to use for labeling.
base : int, optional
For frequencies that evenly subdivide 1 day, the "origin" of the
aggregated intervals. For example, for "24H" frequency, base could
range from 0 through 23.
origin : {'epoch', 'start', 'start_day', 'end', 'end_day'}, pd.Timestamp, datetime.datetime, np.datetime64, or cftime.datetime, default 'start_day'
The datetime on which to adjust the grouping. The timezone of origin
must match the timezone of the index.
Expand All @@ -10708,15 +10707,6 @@ def resample(
- 'end_day': `origin` is the ceiling midnight of the last day
offset : pd.Timedelta, datetime.timedelta, or str, default is None
An offset timedelta added to the origin.
loffset : timedelta or str, optional
Offset used to adjust the resampled time labels. Some pandas date
offset strings are supported.
.. deprecated:: 2023.03.0
Following pandas, the ``loffset`` parameter is deprecated in favor
of using time offset arithmetic, and will be removed in a future
version of xarray.
restore_coord_dims : bool, optional
If True, also restore the dimension order of multi-dimensional
coordinates.
Expand Down Expand Up @@ -10749,10 +10739,8 @@ def resample(
skipna=skipna,
closed=closed,
label=label,
base=base,
offset=offset,
origin=origin,
loffset=loffset,
restore_coord_dims=restore_coord_dims,
**indexer_kwargs,
)
Expand Down
Loading

0 comments on commit 5e61d14

Please sign in to comment.