-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Support keyword API for Dataset.drop
#3128
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3128 +/- ##
==========================================
+ Coverage 95.66% 95.98% +0.31%
==========================================
Files 64 63 -1
Lines 13117 12788 -329
==========================================
- Hits 12548 12274 -274
+ Misses 569 514 -55 |
Awesome, thanks for working on this @gwgundersen ! In the long term, we might want to deprecate the current function signature, but I'm happy to leave that for later. |
@gwgundersen I see you trying to merge re the recent black changes. Here are the instructions for making this (relatively) seamless: https://github.com/pydata/xarray/blob/d3f1ced1aa84cb0a0f3e47e7ee67492e203fcce5/doc/contributing.rst#code-formatting |
@max-sixty, thanks! It's useful to be able to do in advance. After merging from master, I get this error:
I assume this is due to #3177 cc @crusaderky. Is there a way to avoid this? |
@gwgundersen Could you force-push your latest code? If your current latest code is pushed, you may have to |
97271bd
to
1de442e
Compare
Hello @gwgundersen! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2019-08-18 07:25:58 UTC |
Sorry about that. I'm not sure what happened. I've reverted branch and cherry picked my changes. The issue with |
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.
Added a noqa
suggestion so flake doesn't complain
Thanks @gwgundersen - good idea re the cherry pick for more discrete changes. Still getting a test failure though, check it out and lmk if you need any help |
Now the docs don't build. When I try to build locally, I get a vague error: File "/Users/gwg/miniconda3/envs/xarray-docs/lib/python3.7/site-packages/IPython/sphinxext/ipython_directive.py", line 583, in process_input
raise RuntimeError('Non Expected warning in `{}` line {}'.format(filename, lineno))
RuntimeError: Non Expected warning in `/Users/gwg/projects/xarray/doc/indexing.rst` line 241 Do you see anything wrong with this? The :py:meth:`~xarray.Dataset.drop` method returns a new object with the listed
index labels along a dimension dropped:
.. ipython:: python
ds.drop(['IN', 'IL'], dim='space')
<-- line 241
``drop`` is both a ``Dataset`` and ``DataArray`` method.
Use :py:meth:`~xarray.Dataset.drop_dims` to drop a full dimension from a Dataset.
Any variables with these dimensions are also dropped: |
It looks like you've added a warming for this case. So you'll need to specify :okwarning: . |
I see the docs timing out after 60 min. I also see that message, but is that causing the failure? I restarted the docs build to see whether that might help |
Sorry for the back-and-forth. CI tests and checks are all passing, and this is ready for another review. |
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.
Super! Will merge tomorrow unless anyone has comments?
@gwgundersen could we add a whatsnew too? |
Co-Authored-By: Maximilian Roos <[email protected]>
…into drop-keyword-support
@max-sixty, done. |
Great @gwgundersen ! |
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.
@gwgundersen thanks for this PR!
I have a few minor points that would be good to address before this goes out in an official release.
""" | ||
if errors not in ["raise", "ignore"]: | ||
raise ValueError('errors must be either "raise" or "ignore"') | ||
|
||
if dim is None: | ||
labels_are_coords = isinstance(labels, DataArrayCoordinates) | ||
if labels_kwargs or (utils.is_dict_like(labels) and not labels_are_coords): |
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 wonder if it would be more predictable to special case the dict
type rather than not labels_are_coords
, which is just one of many internal xarray mapping types, e.g.,
if labels_kwargs or (utils.is_dict_like(labels) and not labels_are_coords): | |
if labels_kwargs or isinstance(labels, dict): |
More generally, I get that writing array.drop(array.coords)
is convenient, but in the long term it seems like a bad idea to treat different mapping types differently. This suggests that such uses should be deprecated. Either array.drop_vars(array.coords)
or array.drop(list(array.coords))
would be less ambiguous.
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.
Yeah, I thought needing the check for labels_are_coords
was odd, but I didn't expect passing in coordinates to take a separate code path. Special-casing the dict
type makes sense. And the API that is being deprecated is treating DataArrayCoordinates
as non-dict-like, right?
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.
And the API that is being deprecated is treating
DataArrayCoordinates
as non-dict-like, right?
That's right, we would rather always use this new rule for dict-like inputs.
@@ -236,6 +236,7 @@ The :py:meth:`~xarray.Dataset.drop` method returns a new object with the listed | |||
index labels along a dimension dropped: | |||
|
|||
.. ipython:: python | |||
:okwarning: | |||
|
|||
ds.drop(['IN', 'IL'], dim='space') |
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.
Since this is deprecated, we should fix the docs to use ds.drop(space=['IN', 'IL']
as an example of the preferred syntax going forward.
@shoyer thanks for the follow-up comments. I probably should have spotted those myself. |
Post merge reviews are totally fine. It is not a big deal to revert a merge if needed. |
Happy to make these changes, but what's the protocol here? Seems like reverting the merge and letting me amend is cleaner than me creating a new PR. |
My (limited) understanding of how github handles reverting is that you'll still need to make a new pull request to apply your edits either way. There is no more going to back to amend after PR is merges. The only difference is what the state of "master" looks like when you make your new pull request (whether it includes your partial changes or not). So I don't think it particularly matters if you revert first (as long as the forward fix happens relatively soon), but if you'd prefer to do it that way that's totally fine -- let me know and I will do it. |
I think the easiest way forward is to do a follow-up PR, no need to revert. Reverting would be helpful if we wanted to undo these changes - in this case we have some v marginal additional changes. |
tests/test_dataset
, addedtest_drop_labels_by_keyword
is_list_like
.whats-new.rst
and confirmed API docs built correctly.