Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement GroupBy.__getitem__ #3691

Merged
merged 5 commits into from
Mar 15, 2021
Merged

Implement GroupBy.__getitem__ #3691

merged 5 commits into from
Mar 15, 2021

Conversation

dcherian
Copy link
Contributor

  • Tests added
  • Passes black . && mypy . && flake8
  • Fully documented, including whats-new.rst for all changes and api.rst for new API

Just like the pandas method.

@dcherian dcherian mentioned this pull request Jan 17, 2020
11 tasks
@max-sixty
Copy link
Collaborator

max-sixty commented Mar 5, 2020

As first glance, could this just be __getitem__?

In [9]: xr.DataArray(np.random.rand(2,3),
            coords=dict(y=list('abb')), dims=list('xy')).groupby('y').groups
Out[9]: {'a': [0], 'b': [1, 2]}

In [10]: xr.DataArray(np.random.rand(2,3),
            coords=dict(y=list('abb')), dims=list('xy')).groupby('y')['a']
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-10-84ace5956c1e> in <module>
----> 1 xr.DataArray(np.random.rand(2,3),coords=dict(y=list('abb')), dims=list('xy')).groupby('y')['a']

TypeError: 'DataArrayGroupBy' object is not subscriptable

@dcherian
Copy link
Contributor Author

dcherian commented Feb 6, 2021

@max-sixty Changed to __getitem__ I think that's a good idea.

@dcherian dcherian changed the title Implement GroupBy.get_group Implement GroupBy.__getitem__ Feb 6, 2021
Copy link
Collaborator

@max-sixty max-sixty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks!

* upstream/master:
  fix da.pad example for numpy 1.20 (pydata#4865)
  temporarily pin dask (pydata#4873)
Copy link
Collaborator

@mathause mathause left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I often do dict(groups)[1] but this is more convenient.

@mathause
Copy link
Collaborator

Any objection if I merge this? (I can move the whatsnew entry).

@max-sixty
Copy link
Collaborator

Please @mathause !

@mathause
Copy link
Collaborator

Ok, let's wait for the tests. I'll merge in a day or two.

@mathause mathause merged commit c7c4aae into pydata:master Mar 15, 2021
@mathause
Copy link
Collaborator

Thanks @dcherian

@dcherian dcherian deleted the get_group branch March 15, 2021 11:49
dcherian added a commit to dcherian/xarray that referenced this pull request Mar 18, 2021
…indow

* upstream/master:
  Fix regression in decoding large standard calendar times (pydata#5050)
  Fix sticky sidebar responsiveness on small screens (pydata#5039)
  Flexible indexes refactoring notes (pydata#4979)
  add a install xarray step to the upstream-dev CI (pydata#5044)
  Adds Dataset.query() method, analogous to pandas DataFrame.query() (pydata#4984)
  run tests on python 3.9 (pydata#5040)
  Add date attribute to datetime accessor (pydata#4994)
  📚 New theme & rearrangement of the docs (pydata#4835)
  upgrade ci-trigger to the most recent version (pydata#5037)
  GH5005 fix documentation on open_rasterio (pydata#5021)
  GHA for automatically canceling previous CI runs (pydata#5025)
  Implement GroupBy.__getitem__ (pydata#3691)
  conventions: decode unsigned integers to signed if _Unsigned=false (pydata#4966)
  Added support for numpy.bool_ (pydata#4986)
  Add additional str accessor methods for DataArray (pydata#4622)
dcherian added a commit to dcherian/xarray that referenced this pull request Mar 23, 2021
…-tasks

* upstream/master:
  Fix regression in decoding large standard calendar times (pydata#5050)
  Fix sticky sidebar responsiveness on small screens (pydata#5039)
  Flexible indexes refactoring notes (pydata#4979)
  add a install xarray step to the upstream-dev CI (pydata#5044)
  Adds Dataset.query() method, analogous to pandas DataFrame.query() (pydata#4984)
  run tests on python 3.9 (pydata#5040)
  Add date attribute to datetime accessor (pydata#4994)
  📚 New theme & rearrangement of the docs (pydata#4835)
  upgrade ci-trigger to the most recent version (pydata#5037)
  GH5005 fix documentation on open_rasterio (pydata#5021)
  GHA for automatically canceling previous CI runs (pydata#5025)
  Implement GroupBy.__getitem__ (pydata#3691)
  conventions: decode unsigned integers to signed if _Unsigned=false (pydata#4966)
  Added support for numpy.bool_ (pydata#4986)
  Add additional str accessor methods for DataArray (pydata#4622)
  add polyval to polyfit see also (pydata#5020)
  mention map_blocks in the docstring of apply_ufunc (pydata#5011)
  Switch backend API to v2 (pydata#4989)
  WIP: add new backend api documentation (pydata#4810)
  pin netCDF4=1.5.3 in min-all-deps (pydata#4982)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants