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_bins sorts bin labels as strings #952

Closed
shoyer opened this issue Aug 8, 2016 · 1 comment
Closed

groupby_bins sorts bin labels as strings #952

shoyer opened this issue Aug 8, 2016 · 1 comment
Labels

Comments

@shoyer
Copy link
Member

shoyer commented Aug 8, 2016

This sometimes gets them out of order:

import xarray as xr
import numpy as np
data = xr.DataArray(np.arange(100), dims='x', coords={'x': np.linspace(-100, 100, num=100)})
print(data.groupby_bins('x', bins=11).mean().to_series())
x_bins
(-100.2, -81.818]      4.5
(-27.273, -9.0909]    41.0
(-45.455, -27.273]    32.0
(-63.636, -45.455]    23.0
(-81.818, -63.636]    14.0
(-9.0909, 9.0909]     50.0
(27.273, 45.455]      68.0
(45.455, 63.636]      77.0
(63.636, 81.818]      86.0
(81.818, 100]         95.0
(9.0909, 27.273]      59.0
dtype: float64

We should pass through sort=False to pd.factorize in groupby.unique_value_groups when using bins to avoid this.

CC @chrisroat @rabernat

@rabernat
Copy link
Contributor

rabernat commented Aug 8, 2016

Good catch. Should be an easy fix. I can put together a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants