Skip to content

Commit aeae28d

Browse files
committed
Allow None too
1 parent 2cc5375 commit aeae28d

File tree

6 files changed

+31
-19
lines changed

6 files changed

+31
-19
lines changed

doc/whats-new.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Deprecations
4343
~~~~~~~~~~~~
4444

4545
- The deprecation cycle for the ``eagerly_compute_group`` kwarg to ``groupby`` and ``groupby_bins``
46-
is now complete. The only acceptable value now is ``False``.
46+
is now complete.
4747
By `Deepak Cherian <https://github.com/dcherian>`_.
4848

4949
Bug fixes

xarray/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ def _resample(
11181118
f"Received {type(freq)} instead."
11191119
)
11201120

1121-
rgrouper = ResolvedGrouper(grouper, group, self, eagerly_compute_group=False)
1121+
rgrouper = ResolvedGrouper(grouper, group, self)
11221122

11231123
return resample_cls(
11241124
self,

xarray/core/dataarray.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6813,7 +6813,7 @@ def groupby(
68136813
*,
68146814
squeeze: Literal[False] = False,
68156815
restore_coord_dims: bool = False,
6816-
eagerly_compute_group: Literal[False] = False,
6816+
eagerly_compute_group: Literal[False] | None = None,
68176817
**groupers: Grouper,
68186818
) -> DataArrayGroupBy:
68196819
"""Returns a DataArrayGroupBy object for performing grouped operations.
@@ -6962,7 +6962,7 @@ def groupby_bins(
69626962
squeeze: Literal[False] = False,
69636963
restore_coord_dims: bool = False,
69646964
duplicates: Literal["raise", "drop"] = "raise",
6965-
eagerly_compute_group: Literal[False] = False,
6965+
eagerly_compute_group: Literal[False] | None = None,
69666966
) -> DataArrayGroupBy:
69676967
"""Returns a DataArrayGroupBy object for performing grouped operations.
69686968

xarray/core/dataset.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9824,7 +9824,7 @@ def groupby(
98249824
*,
98259825
squeeze: Literal[False] = False,
98269826
restore_coord_dims: bool = False,
9827-
eagerly_compute_group: Literal[False] = False,
9827+
eagerly_compute_group: Literal[False] | None = None,
98289828
**groupers: Grouper,
98299829
) -> DatasetGroupBy:
98309830
"""Returns a DatasetGroupBy object for performing grouped operations.
@@ -9892,7 +9892,9 @@ def groupby(
98929892
<xarray.Dataset> Size: 128B
98939893
Dimensions: (y: 3, x_bins: 2, letters: 2)
98949894
Coordinates:
9895-
* x_bins (x_bins) object 16B (5, 15] (15, 25]
9895+
* x_bins (x_b
9896+
9897+
ins) object 16B (5, 15] (15, 25]
98969898
* letters (letters) object 16B 'a' 'b'
98979899
Dimensions without coordinates: y
98989900
Data variables:
@@ -9942,7 +9944,7 @@ def groupby_bins(
99429944
squeeze: Literal[False] = False,
99439945
restore_coord_dims: bool = False,
99449946
duplicates: Literal["raise", "drop"] = "raise",
9945-
eagerly_compute_group: Literal[False] = False,
9947+
eagerly_compute_group: Literal[False] | None = None,
99469948
) -> DatasetGroupBy:
99479949
"""Returns a DatasetGroupBy object for performing grouped operations.
99489950

xarray/core/groupby.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
FrozenMappingWarningOnValuesAccess,
4343
contains_only_chunked_or_numpy,
4444
either_dict_or_kwargs,
45+
emit_user_level_warning,
4546
hashable,
4647
is_scalar,
4748
maybe_wrap_array,
@@ -293,7 +294,7 @@ class ResolvedGrouper(Generic[T_DataWithCoords]):
293294
grouper: Grouper
294295
group: T_Group
295296
obj: T_DataWithCoords
296-
eagerly_compute_group: Literal[False] = field(repr=False)
297+
eagerly_compute_group: Literal[False] | None = field(repr=False, default=None)
297298

298299
# returned by factorize:
299300
encoded: EncodedGroups = field(init=False, repr=False)
@@ -322,7 +323,7 @@ def __post_init__(self) -> None:
322323

323324
self.group = _resolve_group(self.obj, self.group)
324325

325-
if self.eagerly_compute_group is not False:
326+
if self.eagerly_compute_group:
326327
raise ValueError(
327328
f""""Eagerly computing the DataArray you're grouping by ({self.group.name!r}) "
328329
has been removed.
@@ -332,6 +333,11 @@ def __post_init__(self) -> None:
332333
or (2) pass explicit bin edges using ``bins`` or
333334
`.groupby({self.group.name}=BinGrouper(bins=...))`; as appropriate."""
334335
)
336+
if self.eagerly_compute_group is not None:
337+
emit_user_level_warning(
338+
"Passing `eagerly_compute_group` is now deprecated. It has no effect.",
339+
DeprecationWarning,
340+
)
335341

336342
if not isinstance(self.group, _DummyGroup) and is_chunked_array(
337343
self.group.variable._data

xarray/tests/test_groupby.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3089,9 +3089,7 @@ def test_lazy_grouping(grouper, expect_index):
30893089

30903090
if has_flox:
30913091
lazy = (
3092-
xr.Dataset({"foo": data}, coords={"zoo": data})
3093-
.groupby(zoo=grouper, eagerly_compute_group=False)
3094-
.count()
3092+
xr.Dataset({"foo": data}, coords={"zoo": data}).groupby(zoo=grouper).count()
30953093
)
30963094
assert_identical(eager, lazy)
30973095

@@ -3107,9 +3105,7 @@ def test_lazy_grouping_errors() -> None:
31073105
coords={"y": ("x", dask.array.arange(20, chunks=3))},
31083106
)
31093107

3110-
gb = data.groupby(
3111-
y=UniqueGrouper(labels=np.arange(5, 10)), eagerly_compute_group=False
3112-
)
3108+
gb = data.groupby(y=UniqueGrouper(labels=np.arange(5, 10)))
31133109
message = "not supported when lazily grouping by"
31143110
with pytest.raises(ValueError, match=message):
31153111
gb.map(lambda x: x)
@@ -3253,18 +3249,26 @@ def test_groupby_dask_eager_load_warnings() -> None:
32533249
).chunk(z=6)
32543250

32553251
with pytest.raises(ValueError, match="Please pass"):
3256-
ds.groupby("x", eagerly_compute_group=False)
3252+
with pytest.warns(DeprecationWarning):
3253+
ds.groupby("x", eagerly_compute_group=False)
3254+
with pytest.raises(ValueError, match="Eagerly computing"):
3255+
ds.groupby("x", eagerly_compute_group=True)
32573256

32583257
# This is technically fine but anyone iterating over the groupby object
32593258
# will see an error, so let's warn and have them opt-in.
32603259
ds.groupby(x=UniqueGrouper(labels=[1, 2, 3]))
32613260

3262-
ds.groupby(x=UniqueGrouper(labels=[1, 2, 3]), eagerly_compute_group=False)
3261+
with pytest.warns(DeprecationWarning):
3262+
ds.groupby(x=UniqueGrouper(labels=[1, 2, 3]), eagerly_compute_group=False)
32633263

32643264
with pytest.raises(ValueError, match="Please pass"):
3265-
ds.groupby_bins("x", bins=3, eagerly_compute_group=False)
3265+
with pytest.warns(DeprecationWarning):
3266+
ds.groupby_bins("x", bins=3, eagerly_compute_group=False)
3267+
with pytest.raises(ValueError, match="Eagerly computing"):
3268+
ds.groupby_bins("x", bins=3, eagerly_compute_group=True)
32663269
ds.groupby_bins("x", bins=[1, 2, 3])
3267-
ds.groupby_bins("x", bins=[1, 2, 3], eagerly_compute_group=False)
3270+
with pytest.warns(DeprecationWarning):
3271+
ds.groupby_bins("x", bins=[1, 2, 3], eagerly_compute_group=False)
32683272

32693273

32703274
# TODO: Possible property tests to add to this module

0 commit comments

Comments
 (0)