Skip to content

BUG: fix+test groupby on empty DataArray raises StopIteration #3156

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

Merged
merged 4 commits into from
Jul 23, 2019

Conversation

HasanAhmadQ7
Copy link
Contributor

Using groupby on an empty DataArray or Dataset raises StopIteration. It should raise a more meaningful error.

@pep8speaks
Copy link

pep8speaks commented Jul 21, 2019

Hello @HasanAhmadQ7! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-07-22 21:36:39 UTC

@HasanAhmadQ7 HasanAhmadQ7 force-pushed the fix_bug_groupby_on_empty_da branch from 41dc039 to 4365705 Compare July 21, 2019 11:32
@HasanAhmadQ7 HasanAhmadQ7 changed the title BUG: groupby on empty DataArray raises StopIteration BUG: fix+test groupby on empty DataArray raises StopIteration Jul 21, 2019
@HasanAhmadQ7 HasanAhmadQ7 force-pushed the fix_bug_groupby_on_empty_da branch from 4365705 to eecf4ae Compare July 21, 2019 11:35
Using groupby on an empty DataArray or Dataset raises StopIteration. It should raise a more meaningful error.

Resolves: 3037
@HasanAhmadQ7 HasanAhmadQ7 force-pushed the fix_bug_groupby_on_empty_da branch from eecf4ae to 39e58b2 Compare July 21, 2019 11:37
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.

Thanks @HasanAhmadQ7 , happy to have you as a contributor

Do you want to add this change to whatnew?
I also left a comment re an even friendlier error message

Then I'll merge tomorrow unless anyone else has comments

@@ -232,6 +232,9 @@ def __init__(self, obj, group, squeeze=False, grouper=None, bins=None,
raise TypeError('`group` must be an xarray.DataArray or the '
'name of an xarray variable or dimension')
group = obj[group]
if len(group) == 0:
raise ValueError("Group must not be empty")
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could add the name of the group to the error message?

HasanAhmadQ7 added 2 commits July 22, 2019 09:46
Adding the name of the group to the error message. Making the message more user friendly
@HasanAhmadQ7
Copy link
Contributor Author

@max-sixty I am delighted to be here. Thank you very much!

I modified as per your comments, please let me know if there are further modifications .

Co-Authored-By: Maximilian Roos <[email protected]>
@max-sixty max-sixty merged commit 1d7bcbd into pydata:master Jul 23, 2019
@max-sixty
Copy link
Collaborator

Thanks @HasanAhmadQ7 !

@HasanAhmadQ7 HasanAhmadQ7 deleted the fix_bug_groupby_on_empty_da branch July 23, 2019 02:04
dcherian added a commit to yohai/xarray that referenced this pull request Aug 3, 2019
* master: (68 commits)
  enable sphinx.ext.napoleon (pydata#3180)
  remove type annotations from autodoc method signatures (pydata#3179)
  Fix regression: IndexVariable.copy(deep=True) casts dtype=U to object (pydata#3095)
  Fix distributed.Client.compute applied to DataArray (pydata#3173)
  More annotations in Dataset (pydata#3112)
  Hotfix for case of combining identical non-monotonic coords (pydata#3151)
  changed url for rasterio network test (pydata#3162)
  to_zarr(append_dim='dim0') doesn't need mode='a' (pydata#3123)
  BUG: fix+test groupby on empty DataArray raises StopIteration (pydata#3156)
  Temporarily remove pynio from py36 CI build (pydata#3157)
  missing 'about' field (pydata#3146)
  Fix h5py version printing (pydata#3145)
  Remove the matplotlib=3.0 constraint from py36.yml (pydata#3143)
  disable codecov comments (pydata#3140)
  Merge broadcast_like docstrings, analyze implementation problem (pydata#3130)
  Update whats-new for pydata#3125 and pydata#2334 (pydata#3135)
  Fix tests on big-endian systems (pydata#3125)
  XFAIL tests failing on ARM (pydata#2334)
  Add broadcast_like. (pydata#3086)
  Better docs and errors about expand_dims() view (pydata#3114)
  ...
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.

groupby on empty DataArray raises StopIteration
3 participants