-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add drop_isel #4819
Add drop_isel #4819
Conversation
- Use get_index(dim) in drop_sel - Add drop_isel
47cbca9
to
1617485
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is excellent! Thanks @mesejo
I added a couple of minor comments.
It would be great to do this for DataArray
too — it can be a very simple wrapper of this method.
LGTM!
Just to add on to this - the wrapper can be written as: class DataArray:
...
def drop_isel(self, indexers=None, **indexers_kwargs):
"""Drop index positions from this dataset.
...
"""
dataset = self._to_temp_dataset()
dataset = dataset.drop_isel(indexers=indexers, **indexers_kwargs)
return self._from_temp_dataset(dataset)
... |
Thanks for the feedback. I've addressed the issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thanks @mesejo !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I added two suggestions but it's also fine to merge as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are a few more issues we should address in a new PR
A (x, y) int64 0 2 3 5 | ||
""" | ||
|
||
indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "drop") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "drop") | |
indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "drop_isel") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one we should change — @mesejo would you be up for putting the one-line PR in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I can do it. No problem, but just to be sure, drop_sel
also has:
labels = either_dict_or_kwargs(labels, labels_kwargs, "drop")
Should I change it also? BTW drop_sel
also uses np.random.randn
in the docstrings should I change this also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good spot, that's a mistake, it should be "drop_sel")
We're trying to move away from random values in the docstrings, but it's not urgent — if you can that would be appreciated, but correcting this & #4819 (comment) is fine to do alone.
Thank you!
@@ -2327,6 +2327,12 @@ def test_drop_index_labels(self): | |||
with pytest.warns(DeprecationWarning): | |||
arr.drop([0, 1, 3], dim="y", errors="ignore") | |||
|
|||
def test_drop_index_positions(self): | |||
arr = DataArray(np.random.randn(2, 3), dims=["x", "y"]) | |||
actual = arr.drop_sel(y=[0, 1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it intentional that you use drop_sel
here? This succeeds because of the change to Edit: as it turns out, self.get_index(dim)
in drop_sel
, but it really should fail.drop_sel
is consistent with sel
now, so I guess it makes sense that this does not fail. However, since the test is called test_drop_index_positions
I still think this is a typo:
actual = arr.drop_sel(y=[0, 1]) | |
actual = arr.drop_isel(y=[0, 1]) |
Thanks for spotting these @keewis, sorry I missed them. On the
I tend to agree, but |
I suggested using |
I agree it's important to be consistent with Also, neither |
* upstream/master: Bugfix in list_engine (pydata#4811) Add drop_isel (pydata#4819) Fix RST. Remove the references to `_file_obj` outside low level code paths, change to `_close` (pydata#4809)
* upstream/master: speed up the repr for big MultiIndex objects (pydata#4846) dim -> coord in DataArray.integrate (pydata#3993) WIP: backend interface, now it uses subclassing (pydata#4836) weighted: small improvements (pydata#4818) Update related-projects.rst (pydata#4844) iris update doc url (pydata#4845) Faster unstacking (pydata#4746) Allow swap_dims to take kwargs (pydata#4841) Move skip ci instructions to contributing guide (pydata#4829) fix issues in drop_sel and drop_isel (pydata#4828) Bugfix in list_engine (pydata#4811) Add drop_isel (pydata#4819) Fix RST. Remove the references to `_file_obj` outside low level code paths, change to `_close` (pydata#4809)
* master: (458 commits) Add units if "unit" is in the attrs. (pydata#4850) speed up the repr for big MultiIndex objects (pydata#4846) dim -> coord in DataArray.integrate (pydata#3993) WIP: backend interface, now it uses subclassing (pydata#4836) weighted: small improvements (pydata#4818) Update related-projects.rst (pydata#4844) iris update doc url (pydata#4845) Faster unstacking (pydata#4746) Allow swap_dims to take kwargs (pydata#4841) Move skip ci instructions to contributing guide (pydata#4829) fix issues in drop_sel and drop_isel (pydata#4828) Bugfix in list_engine (pydata#4811) Add drop_isel (pydata#4819) Fix RST. Remove the references to `_file_obj` outside low level code paths, change to `_close` (pydata#4809) fix decode for scale/ offset list (pydata#4802) Expand user dir paths (~) in open_mfdataset and to_zarr. (pydata#4795) add a version info step to the upstream-dev CI (pydata#4815) fix the ci trigger action (pydata#4805) scatter plot by order of the first appearance of hue (pydata#4723) ...
pre-commit run --all-files
whats-new.rst
api.rst