-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add "unique()" method, mimicking pandas #2795
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
Comments
What would I don't see a lot of value in adding this to xarray, given that all the xarray metadata gets lost by the |
Right, it would return a 1D numpy or dask array. I suppose I'm used to simply typing pd.Series().unique() rather than np.unique(pd.Series()). I use it in for loops primarily. |
Hi, I also vote for this function, My typical use-case. There is some structure in 3D space and I need to "flatten it" to 2D. Let us say it is axially symetric so I assign R and Z coordinate to points (or r and theta in polar). And I want to simplify this using I have some solution here: https://stackoverflow.com/questions/51058379/drop-duplicate-times-in-xarray and adapted this into actuall function: def distribure_uniform(ds, N_points=512):
ds_theta = ds.sortby("theta").swap_dims({"idx": "theta"})
_, index = np.unique(ds_theta['theta'], return_index=True)
ds_theta = ds_theta.isel(theta=index)
ds_theta = ds_theta.interp(
theta=np.linspace(ds.theta.min(), ds.theta.max(), N_points))
ds_theta = ds_theta.swap_dims({"theta": "idx"})
return ds_theta In an idal case I would like to write something like this: def distribure_uniform(ds, N_points=512):
ds_theta= ds.unique("theta", sorted=False, sort=True)
ds_theta = ds_theta.swap_dims({"idx": "theta"})
ds_theta = ds_theta.interp(
theta=np.linspace(ds.theta.min(), ds.theta.max(), N_points))
ds_theta = ds_theta.swap_dims({"theta": "idx"})
return ds_theta |
A case I ran into where supporting .unique() in the pandas sense would be helpful is when an object dtype is used to support nullable strings:
|
Actually, |
I guess the limitation on using pd.unique() is that it requires 1D data. |
Would it be good to add a unique() method that mimics pandas?
Output:
The text was updated successfully, but these errors were encountered: