Skip to content

Commit 5e61d14

Browse files
committed
Merge branch 'main' into chunk-by-frequency
* main: Delete ``base`` and ``loffset`` parameters to resample (pydata#9233) Update dropna docstring (pydata#9257)
2 parents 5c39645 + 39d5b39 commit 5e61d14

File tree

9 files changed

+43
-402
lines changed

9 files changed

+43
-402
lines changed

doc/whats-new.rst

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

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

4954

5055
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
@@ -7249,10 +7249,8 @@ def resample(
72497249
skipna: bool | None = None,
72507250
closed: SideOptions | None = None,
72517251
label: SideOptions | None = None,
7252-
base: int | None = None,
72537252
offset: pd.Timedelta | datetime.timedelta | str | None = None,
72547253
origin: str | DatetimeLike = "start_day",
7255-
loffset: datetime.timedelta | str | None = None,
72567254
restore_coord_dims: bool | None = None,
72577255
**indexer_kwargs: str | Resampler,
72587256
) -> DataArrayResample:
@@ -7274,10 +7272,6 @@ def resample(
72747272
Side of each interval to treat as closed.
72757273
label : {"left", "right"}, optional
72767274
Side of each interval to use for labeling.
7277-
base : int, optional
7278-
For frequencies that evenly subdivide 1 day, the "origin" of the
7279-
aggregated intervals. For example, for "24H" frequency, base could
7280-
range from 0 through 23.
72817275
origin : {'epoch', 'start', 'start_day', 'end', 'end_day'}, pd.Timestamp, datetime.datetime, np.datetime64, or cftime.datetime, default 'start_day'
72827276
The datetime on which to adjust the grouping. The timezone of origin
72837277
must match the timezone of the index.
@@ -7290,15 +7284,6 @@ def resample(
72907284
- 'end_day': `origin` is the ceiling midnight of the last day
72917285
offset : pd.Timedelta, datetime.timedelta, or str, default is None
72927286
An offset timedelta added to the origin.
7293-
loffset : timedelta or str, optional
7294-
Offset used to adjust the resampled time labels. Some pandas date
7295-
offset strings are supported.
7296-
7297-
.. deprecated:: 2023.03.0
7298-
Following pandas, the ``loffset`` parameter is deprecated in favor
7299-
of using time offset arithmetic, and will be removed in a future
7300-
version of xarray.
7301-
73027287
restore_coord_dims : bool, optional
73037288
If True, also restore the dimension order of multi-dimensional
73047289
coordinates.
@@ -7403,10 +7388,8 @@ def resample(
74037388
skipna=skipna,
74047389
closed=closed,
74057390
label=label,
7406-
base=base,
74077391
offset=offset,
74087392
origin=origin,
7409-
loffset=loffset,
74107393
restore_coord_dims=restore_coord_dims,
74117394
**indexer_kwargs,
74127395
)

xarray/core/dataset.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6412,7 +6412,7 @@ def dropna(
64126412
Data variables:
64136413
temperature (time, location) float64 64B 23.4 24.1 nan ... 24.2 20.5 25.3
64146414
6415-
# Drop NaN values from the dataset
6415+
Drop NaN values from the dataset
64166416
64176417
>>> dataset.dropna(dim="time")
64186418
<xarray.Dataset> Size: 80B
@@ -6423,7 +6423,7 @@ def dropna(
64236423
Data variables:
64246424
temperature (time, location) float64 48B 23.4 24.1 21.8 24.2 20.5 25.3
64256425
6426-
# Drop labels with any NAN values
6426+
Drop labels with any NaN values
64276427
64286428
>>> dataset.dropna(dim="time", how="any")
64296429
<xarray.Dataset> Size: 80B
@@ -6434,7 +6434,7 @@ def dropna(
64346434
Data variables:
64356435
temperature (time, location) float64 48B 23.4 24.1 21.8 24.2 20.5 25.3
64366436
6437-
# Drop labels with all NAN values
6437+
Drop labels with all NAN values
64386438
64396439
>>> dataset.dropna(dim="time", how="all")
64406440
<xarray.Dataset> Size: 104B
@@ -6445,7 +6445,7 @@ def dropna(
64456445
Data variables:
64466446
temperature (time, location) float64 64B 23.4 24.1 nan ... 24.2 20.5 25.3
64476447
6448-
# Drop labels with less than 2 non-NA values
6448+
Drop labels with less than 2 non-NA values
64496449
64506450
>>> dataset.dropna(dim="time", thresh=2)
64516451
<xarray.Dataset> Size: 80B
@@ -6459,6 +6459,11 @@ def dropna(
64596459
Returns
64606460
-------
64616461
Dataset
6462+
6463+
See Also
6464+
--------
6465+
DataArray.dropna
6466+
pandas.DataFrame.dropna
64626467
"""
64636468
# TODO: consider supporting multiple dimensions? Or not, given that
64646469
# there are some ugly edge cases, e.g., pandas's dropna differs
@@ -10667,10 +10672,8 @@ def resample(
1066710672
skipna: bool | None = None,
1066810673
closed: SideOptions | None = None,
1066910674
label: SideOptions | None = None,
10670-
base: int | None = None,
1067110675
offset: pd.Timedelta | datetime.timedelta | str | None = None,
1067210676
origin: str | DatetimeLike = "start_day",
10673-
loffset: datetime.timedelta | str | None = None,
1067410677
restore_coord_dims: bool | None = None,
1067510678
**indexer_kwargs: str | Resampler,
1067610679
) -> DatasetResample:
@@ -10692,10 +10695,6 @@ def resample(
1069210695
Side of each interval to treat as closed.
1069310696
label : {"left", "right"}, optional
1069410697
Side of each interval to use for labeling.
10695-
base : int, optional
10696-
For frequencies that evenly subdivide 1 day, the "origin" of the
10697-
aggregated intervals. For example, for "24H" frequency, base could
10698-
range from 0 through 23.
1069910698
origin : {'epoch', 'start', 'start_day', 'end', 'end_day'}, pd.Timestamp, datetime.datetime, np.datetime64, or cftime.datetime, default 'start_day'
1070010699
The datetime on which to adjust the grouping. The timezone of origin
1070110700
must match the timezone of the index.
@@ -10708,15 +10707,6 @@ def resample(
1070810707
- 'end_day': `origin` is the ceiling midnight of the last day
1070910708
offset : pd.Timedelta, datetime.timedelta, or str, default is None
1071010709
An offset timedelta added to the origin.
10711-
loffset : timedelta or str, optional
10712-
Offset used to adjust the resampled time labels. Some pandas date
10713-
offset strings are supported.
10714-
10715-
.. deprecated:: 2023.03.0
10716-
Following pandas, the ``loffset`` parameter is deprecated in favor
10717-
of using time offset arithmetic, and will be removed in a future
10718-
version of xarray.
10719-
1072010710
restore_coord_dims : bool, optional
1072110711
If True, also restore the dimension order of multi-dimensional
1072210712
coordinates.
@@ -10749,10 +10739,8 @@ def resample(
1074910739
skipna=skipna,
1075010740
closed=closed,
1075110741
label=label,
10752-
base=base,
1075310742
offset=offset,
1075410743
origin=origin,
10755-
loffset=loffset,
1075610744
restore_coord_dims=restore_coord_dims,
1075710745
**indexer_kwargs,
1075810746
)

0 commit comments

Comments
 (0)