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

drop_sel indices in dimension that doesn't have coordinates? #4658

Closed
shaunc opened this issue Dec 7, 2020 · 3 comments · Fixed by #4819
Closed

drop_sel indices in dimension that doesn't have coordinates? #4658

shaunc opened this issue Dec 7, 2020 · 3 comments · Fixed by #4819

Comments

@shaunc
Copy link

shaunc commented Dec 7, 2020

Is your feature request related to a problem? Please describe.

I am trying to drop particular indices from a dimension that doesn't have coordinates.

Following: drop_sel() documentation,
but leaving out the coordinate labels:

data = np.random.randn(2, 3)
ds = xr.Dataset({"A": (["x", "y"], data)})
ds.drop_sel(y=[1])

gives me an error.

Describe the solution you'd like

I would think drop_isel should exist and work in analogy to drop_sel as isel does to sel.

Describe alternatives you've considered

As far as I know, I could either create coordinates especially to in order to drop, or rebuild a new dataset. Both are not congenial. (I'd be grateful to know if there is actually a straightforward way to do this I've overlooked.

@mathause
Copy link
Collaborator

mathause commented Dec 7, 2020

I don't know of an easy way (which does not mean that there is none). drop_sel could be adjusted to work with dimensions without coordinates by replacing

index = self.indexes[dim]

by index = self.get_index(dim). That would then be analog to sel. I think drop_isel would also be a welcome addition.

@dcherian dcherian changed the title question/feature request: how to drop indices in dimension that doesn't have coordinates? drop_sel indices in dimension that doesn't have coordinates? Dec 7, 2020
@mesejo
Copy link
Contributor

mesejo commented Jan 5, 2021

Can I work on this?

@dcherian
Copy link
Contributor

dcherian commented Jan 6, 2021

Sure. PRs are always welcome!

mesejo added a commit to mesejo/xarray that referenced this issue Jan 17, 2021
- Use get_index(dim) in drop_sel
- Add drop_isel
@mesejo mesejo mentioned this issue Jan 17, 2021
4 tasks
mesejo added a commit to mesejo/xarray that referenced this issue Jan 17, 2021
- Use get_index(dim) in drop_sel
- Add drop_isel
max-sixty pushed a commit that referenced this issue Jan 18, 2021
* Closes #4658

- Use get_index(dim) in drop_sel
- Add drop_isel

* address issues in PR

* extract dict creation out of the loop
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