Skip to content

Commit b35f761

Browse files
dcherianheadtr1ckpre-commit-ci[bot]
authored
Deprecate squeeze in GroupBy. (#8507)
* Deprecate `squeeze` in GroupBy. Closes #2157 * silence warnings * better warning * Fix first, last * Set squeeze=None for Dataset too * Update xarray/tests/test_groupby.py * Test one more warning * Reduce more warnings * fix whats-new * Fix docs * Fix generator for aggregations * Fix typing * Add tests for #8263 * minimize test mods * Silence more warnings * Apply suggestions from code review Co-authored-by: Michael Niklas <mick.niklas@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Don't skip for resampling --------- Co-authored-by: Michael Niklas <mick.niklas@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 492aa07 commit b35f761

File tree

12 files changed

+638
-171
lines changed

12 files changed

+638
-171
lines changed

doc/user-guide/groupby.rst

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,28 +177,18 @@ This last line is roughly equivalent to the following::
177177
results.append(group - alt.sel(letters=label))
178178
xr.concat(results, dim='x')
179179

180-
Squeezing
181-
~~~~~~~~~
180+
Iterating and Squeezing
181+
~~~~~~~~~~~~~~~~~~~~~~~
182182

183-
When grouping over a dimension, you can control whether the dimension is
184-
squeezed out or if it should remain with length one on each group by using
185-
the ``squeeze`` parameter:
186-
187-
.. ipython:: python
188-
189-
next(iter(arr.groupby("x")))
183+
Previously, Xarray defaulted to squeezing out dimensions of size one when iterating over
184+
a GroupBy object. This behaviour is being removed.
185+
You can always squeeze explicitly later with the Dataset or DataArray
186+
:py:meth:`~xarray.DataArray.squeeze` methods.
190187

191188
.. ipython:: python
192189
193190
next(iter(arr.groupby("x", squeeze=False)))
194191
195-
Although xarray will attempt to automatically
196-
:py:attr:`~xarray.DataArray.transpose` dimensions back into their original order
197-
when you use apply, it is sometimes useful to set ``squeeze=False`` to
198-
guarantee that all original dimensions remain unchanged.
199-
200-
You can always squeeze explicitly later with the Dataset or DataArray
201-
:py:meth:`~xarray.DataArray.squeeze` methods.
202192
203193
.. _groupby.multidim:
204194

doc/whats-new.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ Breaking changes
5757

5858
Deprecations
5959
~~~~~~~~~~~~
60-
60+
- The `squeeze` kwarg to GroupBy is now deprecated. (:issue:`2157`, :pull:`8507`)
61+
By `Deepak Cherian <https://github.com/dcherian>`_.
6162

6263
Bug fixes
6364
~~~~~~~~~
@@ -141,7 +142,6 @@ Breaking changes
141142

142143
Deprecations
143144
~~~~~~~~~~~~
144-
145145
- As part of an effort to standardize the API, we're renaming the ``dims``
146146
keyword arg to ``dim`` for the minority of functions which current use
147147
``dims``. This started with :py:func:`xarray.dot` & :py:meth:`DataArray.dot`

0 commit comments

Comments
 (0)