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

groupby should still squeeze for non-monotonic inputs #1460

Closed
shoyer opened this issue Jun 19, 2017 · 5 comments · Fixed by #9280
Closed

groupby should still squeeze for non-monotonic inputs #1460

shoyer opened this issue Jun 19, 2017 · 5 comments · Fixed by #9280

Comments

@shoyer
Copy link
Member

shoyer commented Jun 19, 2017

We can simply use argsort() to determine group_indices instead of np.arange():

group_indices = np.arange(group.size)

@stale
Copy link

stale bot commented Sep 29, 2020

In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity

If this issue remains relevant, please comment here or remove the stale label; otherwise it will be marked as closed automatically

@stale stale bot added the stale label Sep 29, 2020
@dcherian dcherian removed the stale label Sep 29, 2020
@dsh0
Copy link

dsh0 commented Jan 24, 2021

I'd like add that the groupby docstring never mention that squeezing only works for monotonic index (which is an unreasonable restriction in the first place)

@shoyer
Copy link
Member Author

shoyer commented Jan 24, 2021

A better long term solution is probably removing "squeeze" from groupby entirely: #2157

@relativistic
Copy link

Just wanted to mention I just got tripped up by this. It took me a long time to figure out why my code wasn't working like the groupby example. It took a lot of trial and error to figure out the problem was one of my dims wasn't sorted. It was a categorical string-based dim that you wouldn't think to sort.

I personally find squeeze a convenient option when applying map. FWIW, it would break some of my code if the default behavior were to change (I'm using map to apply some mathematical code that expects 2d matrix input. The DataArray is 3D, where the third dimension is a label for each 2d matrix). Easy to adapt the code, but I wanted to point out a case where squeeze is what you want.

@shoyer
Copy link
Member Author

shoyer commented Mar 4, 2022

Well, even if we keep squeeze as an option, I think squeeze=False would be much more consistent default behavior :)

dcherian added a commit to dcherian/xarray that referenced this issue Jul 26, 2024
dcherian added a commit to dcherian/xarray that referenced this issue Jul 26, 2024
dcherian added a commit to dcherian/xarray that referenced this issue Jul 26, 2024
dcherian added a commit to dcherian/xarray that referenced this issue Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants