Skip to content

Commit fd53e95

Browse files
committed
Merge branch 'main' into deprecate-grouper-pos-args
* main: Delete ``base`` and ``loffset`` parameters to resample (pydata#9233) Update dropna docstring (pydata#9257)
2 parents 8cd3d14 + 39d5b39 commit fd53e95

File tree

9 files changed

+43
-376
lines changed

9 files changed

+43
-376
lines changed

doc/whats-new.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ New Features
4242

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

4651

4752
Deprecations

xarray/core/common.py

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -881,10 +881,8 @@ def _resample(
881881
skipna: bool | None,
882882
closed: SideOptions | None,
883883
label: SideOptions | None,
884-
base: int | None,
885884
offset: pd.Timedelta | datetime.timedelta | str | None,
886885
origin: str | DatetimeLike,
887-
loffset: datetime.timedelta | str | None,
888886
restore_coord_dims: bool | None,
889887
**indexer_kwargs: str | Resampler,
890888
) -> T_Resample:
@@ -906,16 +904,6 @@ def _resample(
906904
Side of each interval to treat as closed.
907905
label : {"left", "right"}, optional
908906
Side of each interval to use for labeling.
909-
base : int, optional
910-
For frequencies that evenly subdivide 1 day, the "origin" of the
911-
aggregated intervals. For example, for "24H" frequency, base could
912-
range from 0 through 23.
913-
914-
.. deprecated:: 2023.03.0
915-
Following pandas, the ``base`` parameter is deprecated in favor
916-
of the ``origin`` and ``offset`` parameters, and will be removed
917-
in a future version of xarray.
918-
919907
origin : {'epoch', 'start', 'start_day', 'end', 'end_day'}, pd.Timestamp, datetime.datetime, np.datetime64, or cftime.datetime, default 'start_day'
920908
The datetime on which to adjust the grouping. The timezone of origin
921909
must match the timezone of the index.
@@ -928,15 +916,6 @@ def _resample(
928916
- 'end_day': `origin` is the ceiling midnight of the last day
929917
offset : pd.Timedelta, datetime.timedelta, or str, default is None
930918
An offset timedelta added to the origin.
931-
loffset : timedelta or str, optional
932-
Offset used to adjust the resampled time labels. Some pandas date
933-
offset strings are supported.
934-
935-
.. deprecated:: 2023.03.0
936-
Following pandas, the ``loffset`` parameter is deprecated in favor
937-
of using time offset arithmetic, and will be removed in a future
938-
version of xarray.
939-
940919
restore_coord_dims : bool, optional
941920
If True, also restore the dimension order of multi-dimensional
942921
coordinates.
@@ -1072,18 +1051,6 @@ def _resample(
10721051
from xarray.core.groupers import Resampler, TimeResampler
10731052
from xarray.core.resample import RESAMPLE_DIM
10741053

1075-
# note: the second argument (now 'skipna') use to be 'dim'
1076-
if (
1077-
(skipna is not None and not isinstance(skipna, bool))
1078-
or ("how" in indexer_kwargs and "how" not in self.dims)
1079-
or ("dim" in indexer_kwargs and "dim" not in self.dims)
1080-
):
1081-
raise TypeError(
1082-
"resample() no longer supports the `how` or "
1083-
"`dim` arguments. Instead call methods on resample "
1084-
"objects, e.g., data.resample(time='1D').mean()"
1085-
)
1086-
10871054
indexer = either_dict_or_kwargs(indexer, indexer_kwargs, "resample")
10881055
if len(indexer) != 1:
10891056
raise ValueError("Resampling only supported along single dimensions.")
@@ -1093,22 +1060,13 @@ def _resample(
10931060
dim_coord = self[dim]
10941061

10951062
group = DataArray(
1096-
dim_coord,
1097-
coords=dim_coord.coords,
1098-
dims=dim_coord.dims,
1099-
name=RESAMPLE_DIM,
1063+
dim_coord, coords=dim_coord.coords, dims=dim_coord.dims, name=RESAMPLE_DIM
11001064
)
11011065

11021066
grouper: Resampler
11031067
if isinstance(freq, str):
11041068
grouper = TimeResampler(
1105-
freq=freq,
1106-
closed=closed,
1107-
label=label,
1108-
origin=origin,
1109-
offset=offset,
1110-
loffset=loffset,
1111-
base=base,
1069+
freq=freq, closed=closed, label=label, origin=origin, offset=offset
11121070
)
11131071
elif isinstance(freq, Resampler):
11141072
grouper = freq

xarray/core/dataarray.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7250,10 +7250,8 @@ def resample(
72507250
skipna: bool | None = None,
72517251
closed: SideOptions | None = None,
72527252
label: SideOptions | None = None,
7253-
base: int | None = None,
72547253
offset: pd.Timedelta | datetime.timedelta | str | None = None,
72557254
origin: str | DatetimeLike = "start_day",
7256-
loffset: datetime.timedelta | str | None = None,
72577255
restore_coord_dims: bool | None = None,
72587256
**indexer_kwargs: str | Resampler,
72597257
) -> DataArrayResample:
@@ -7275,10 +7273,6 @@ def resample(
72757273
Side of each interval to treat as closed.
72767274
label : {"left", "right"}, optional
72777275
Side of each interval to use for labeling.
7278-
base : int, optional
7279-
For frequencies that evenly subdivide 1 day, the "origin" of the
7280-
aggregated intervals. For example, for "24H" frequency, base could
7281-
range from 0 through 23.
72827276
origin : {'epoch', 'start', 'start_day', 'end', 'end_day'}, pd.Timestamp, datetime.datetime, np.datetime64, or cftime.datetime, default 'start_day'
72837277
The datetime on which to adjust the grouping. The timezone of origin
72847278
must match the timezone of the index.
@@ -7291,15 +7285,6 @@ def resample(
72917285
- 'end_day': `origin` is the ceiling midnight of the last day
72927286
offset : pd.Timedelta, datetime.timedelta, or str, default is None
72937287
An offset timedelta added to the origin.
7294-
loffset : timedelta or str, optional
7295-
Offset used to adjust the resampled time labels. Some pandas date
7296-
offset strings are supported.
7297-
7298-
.. deprecated:: 2023.03.0
7299-
Following pandas, the ``loffset`` parameter is deprecated in favor
7300-
of using time offset arithmetic, and will be removed in a future
7301-
version of xarray.
7302-
73037288
restore_coord_dims : bool, optional
73047289
If True, also restore the dimension order of multi-dimensional
73057290
coordinates.
@@ -7404,10 +7389,8 @@ def resample(
74047389
skipna=skipna,
74057390
closed=closed,
74067391
label=label,
7407-
base=base,
74087392
offset=offset,
74097393
origin=origin,
7410-
loffset=loffset,
74117394
restore_coord_dims=restore_coord_dims,
74127395
**indexer_kwargs,
74137396
)

xarray/core/dataset.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6371,7 +6371,7 @@ def dropna(
63716371
Data variables:
63726372
temperature (time, location) float64 64B 23.4 24.1 nan ... 24.2 20.5 25.3
63736373
6374-
# Drop NaN values from the dataset
6374+
Drop NaN values from the dataset
63756375
63766376
>>> dataset.dropna(dim="time")
63776377
<xarray.Dataset> Size: 80B
@@ -6382,7 +6382,7 @@ def dropna(
63826382
Data variables:
63836383
temperature (time, location) float64 48B 23.4 24.1 21.8 24.2 20.5 25.3
63846384
6385-
# Drop labels with any NAN values
6385+
Drop labels with any NaN values
63866386
63876387
>>> dataset.dropna(dim="time", how="any")
63886388
<xarray.Dataset> Size: 80B
@@ -6393,7 +6393,7 @@ def dropna(
63936393
Data variables:
63946394
temperature (time, location) float64 48B 23.4 24.1 21.8 24.2 20.5 25.3
63956395
6396-
# Drop labels with all NAN values
6396+
Drop labels with all NAN values
63976397
63986398
>>> dataset.dropna(dim="time", how="all")
63996399
<xarray.Dataset> Size: 104B
@@ -6404,7 +6404,7 @@ def dropna(
64046404
Data variables:
64056405
temperature (time, location) float64 64B 23.4 24.1 nan ... 24.2 20.5 25.3
64066406
6407-
# Drop labels with less than 2 non-NA values
6407+
Drop labels with less than 2 non-NA values
64086408
64096409
>>> dataset.dropna(dim="time", thresh=2)
64106410
<xarray.Dataset> Size: 80B
@@ -6418,6 +6418,11 @@ def dropna(
64186418
Returns
64196419
-------
64206420
Dataset
6421+
6422+
See Also
6423+
--------
6424+
DataArray.dropna
6425+
pandas.DataFrame.dropna
64216426
"""
64226427
# TODO: consider supporting multiple dimensions? Or not, given that
64236428
# there are some ugly edge cases, e.g., pandas's dropna differs
@@ -10631,10 +10636,8 @@ def resample(
1063110636
skipna: bool | None = None,
1063210637
closed: SideOptions | None = None,
1063310638
label: SideOptions | None = None,
10634-
base: int | None = None,
1063510639
offset: pd.Timedelta | datetime.timedelta | str | None = None,
1063610640
origin: str | DatetimeLike = "start_day",
10637-
loffset: datetime.timedelta | str | None = None,
1063810641
restore_coord_dims: bool | None = None,
1063910642
**indexer_kwargs: str | Resampler,
1064010643
) -> DatasetResample:
@@ -10656,10 +10659,6 @@ def resample(
1065610659
Side of each interval to treat as closed.
1065710660
label : {"left", "right"}, optional
1065810661
Side of each interval to use for labeling.
10659-
base : int, optional
10660-
For frequencies that evenly subdivide 1 day, the "origin" of the
10661-
aggregated intervals. For example, for "24H" frequency, base could
10662-
range from 0 through 23.
1066310662
origin : {'epoch', 'start', 'start_day', 'end', 'end_day'}, pd.Timestamp, datetime.datetime, np.datetime64, or cftime.datetime, default 'start_day'
1066410663
The datetime on which to adjust the grouping. The timezone of origin
1066510664
must match the timezone of the index.
@@ -10672,15 +10671,6 @@ def resample(
1067210671
- 'end_day': `origin` is the ceiling midnight of the last day
1067310672
offset : pd.Timedelta, datetime.timedelta, or str, default is None
1067410673
An offset timedelta added to the origin.
10675-
loffset : timedelta or str, optional
10676-
Offset used to adjust the resampled time labels. Some pandas date
10677-
offset strings are supported.
10678-
10679-
.. deprecated:: 2023.03.0
10680-
Following pandas, the ``loffset`` parameter is deprecated in favor
10681-
of using time offset arithmetic, and will be removed in a future
10682-
version of xarray.
10683-
1068410674
restore_coord_dims : bool, optional
1068510675
If True, also restore the dimension order of multi-dimensional
1068610676
coordinates.
@@ -10713,10 +10703,8 @@ def resample(
1071310703
skipna=skipna,
1071410704
closed=closed,
1071510705
label=label,
10716-
base=base,
1071710706
offset=offset,
1071810707
origin=origin,
10719-
loffset=loffset,
1072010708
restore_coord_dims=restore_coord_dims,
1072110709
**indexer_kwargs,
1072210710
)

0 commit comments

Comments
 (0)