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_vars; deprecate drop for variables #3475

Merged
merged 17 commits into from
Nov 7, 2019
Merged

Conversation

max-sixty
Copy link
Collaborator

@max-sixty max-sixty commented Oct 31, 2019

Introduces drop_vars, and deprecates using drop for variables. drop is widely used for the deprecated case, so this is a fairly wide blast radius.

It's more churn than is ideal, but I do think it's a much better API.

This is ready for review, though I'm sure I'm missed references in the docs etc (took my peak regex skills to find/replace only the deprecated usages!)

Originally discussed here

  • Tests added
  • Passes black . && mypy . && flake8
  • Fully documented, including whats-new.rst for all changes and api.rst for new API

@shoyer
Copy link
Member

shoyer commented Nov 5, 2019

What do you think about this alternative?

  • Add drop_sel for dropping labels
  • Add drop_vars for variables.
  • Keep around drop as an overloaded alias for both?

(I'm not really sure which is best, to be honest. But keeping down churn does seem like a good idea, if possible.)

@max-sixty
Copy link
Collaborator Author

Yes, that sounds reasonable—I think we move documentation and internal usages to drop_sel and drop_vars, and leave drop as a backward compatible option?

Maybe at last a case for FutureDeprecationWarning :)

@max-sixty
Copy link
Collaborator Author

Updated! I used PendingDeprecationWarning, which is default disabled.

@max-sixty
Copy link
Collaborator Author

@crusaderky let me know if you know off-hand why the MinimumVersionsPolicy is breaking, otherwise I can look into it

@dcherian
Copy link
Contributor

dcherian commented Nov 6, 2019

Add drop_sel for dropping labels

Would drop_labels be better?

@max-sixty
Copy link
Collaborator Author

Would drop_labels be better?

I think either is reasonable. drop_sel has the advantage that it's easily comparable to sel, and has the same arguments, so I'd marginally vote for that. Am easily swayed by popular opinion!

@shoyer
Copy link
Member

shoyer commented Nov 6, 2019 via email

@dcherian
Copy link
Contributor

dcherian commented Nov 6, 2019

👍

@max-sixty
Copy link
Collaborator Author

This is ready to go!

As a reminder, we have PendingDeprecationWarning for drop, which is ignored in user code by default. It does appear in tests, so let me know if that's too strong given the above discussion on backward-compat.

Copy link
Contributor

@dcherian dcherian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. just some minor doc comments

doc/data-structures.rst Show resolved Hide resolved
doc/indexing.rst Show resolved Hide resolved
xarray/core/dataarray.py Show resolved Hide resolved
dropped : Dataset

"""
if isinstance(names, str) or not isinstance(names, Iterable):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this should be isinstance(names, str) or is_scalar(names)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot; I've changed this. But had to keep or not isinstance(names, Iterable): for mypy

@crusaderky as the resident expert, lmk if you have any thoughts on this.

@max-sixty
Copy link
Collaborator Author

Going to merge given @dcherian 's approval, any other follow-ups I can address in another PR

@max-sixty max-sixty merged commit 0e8debf into pydata:master Nov 7, 2019
@max-sixty max-sixty deleted the drop branch November 7, 2019 20:13
dcherian added a commit to dcherian/xarray that referenced this pull request Nov 7, 2019
…tests

* upstream/master:
  drop_vars; deprecate drop for variables (pydata#3475)
  uamiv test using only raw uamiv variables (pydata#3485)
  Optimize dask array equality checks. (pydata#3453)
- :py:meth:`Dataset.drop_sel` & :py:meth:`DataArray.drop_sel` have been added for dropping labels.
:py:meth:`Dataset.drop_vars` & :py:meth:`DataArray.drop_vars` have been added for
dropping variables (including coordinates). The existing ``drop`` methods remain as a backward compatible
option for dropping either lables or variables, but using the more specific methods is encouraged.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lables > labels

@shoyer
Copy link
Member

shoyer commented Nov 7, 2019

Thank you @max-sixty, and @dcherian for reviewing!

@max-sixty max-sixty mentioned this pull request Nov 7, 2019
dcherian added a commit to dcherian/xarray that referenced this pull request Nov 8, 2019
* upstream/master: (27 commits)
  drop_vars; deprecate drop for variables (pydata#3475)
  uamiv test using only raw uamiv variables (pydata#3485)
  Optimize dask array equality checks. (pydata#3453)
  Propagate indexes in DataArray binary operations. (pydata#3481)
  python 3.8 tests (pydata#3477)
  __dask_tokenize__ (pydata#3446)
  Type check sentinel values (pydata#3472)
  Fix typo in docstring (pydata#3474)
  fix test suite warnings re `drop` (pydata#3460)
  Fix integrate docs (pydata#3469)
  Fix leap year condition in monthly means example (pydata#3464)
  Hypothesis tests for roundtrip to & from pandas (pydata#3285)
  unpin cftime (pydata#3463)
  Cleanup whatsnew (pydata#3462)
  enable xr.ALL_DIMS in xr.dot (pydata#3424)
  Merge stable into master (pydata#3457)
  upgrade black verison to 19.10b0 (pydata#3456)
  Remove outdated code related to compatibility with netcdftime (pydata#3450)
  Remove deprecated behavior from dataset.drop docstring (pydata#3451)
  jupyterlab dark theme (pydata#3443)
  ...
dcherian added a commit to dcherian/xarray that referenced this pull request Nov 12, 2019
* upstream/master:
  add missing pint integration tests (pydata#3508)
  DOC: update bottleneck repo url (pydata#3507)
  add drop_sel, drop_vars, map to api.rst (pydata#3506)
  remove syntax warning (pydata#3505)
  Dataset.map, GroupBy.map, Resample.map (pydata#3459)
  tests for datasets with units (pydata#3447)
  fix pandas-dev tests (pydata#3491)
  unpin pseudonetcdf (pydata#3496)
  whatsnew corrections (pydata#3494)
  drop_vars; deprecate drop for variables (pydata#3475)
  uamiv test using only raw uamiv variables (pydata#3485)
  Optimize dask array equality checks. (pydata#3453)
dcherian added a commit to dcherian/xarray that referenced this pull request Nov 13, 2019
* upstream/master:
  format indexing.rst code with black (pydata#3511)
  add missing pint integration tests (pydata#3508)
  DOC: update bottleneck repo url (pydata#3507)
  add drop_sel, drop_vars, map to api.rst (pydata#3506)
  remove syntax warning (pydata#3505)
  Dataset.map, GroupBy.map, Resample.map (pydata#3459)
  tests for datasets with units (pydata#3447)
  fix pandas-dev tests (pydata#3491)
  unpin pseudonetcdf (pydata#3496)
  whatsnew corrections (pydata#3494)
  drop_vars; deprecate drop for variables (pydata#3475)
  uamiv test using only raw uamiv variables (pydata#3485)
  Optimize dask array equality checks. (pydata#3453)
  Propagate indexes in DataArray binary operations. (pydata#3481)
  python 3.8 tests (pydata#3477)
dcherian added a commit to dcherian/xarray that referenced this pull request Nov 13, 2019
commit d430ae0
Author: dcherian <[email protected]>
Date:   Wed Nov 13 08:27:04 2019 -0700

    proper fix.

commit 7fd69be
Author: dcherian <[email protected]>
Date:   Wed Nov 13 08:03:26 2019 -0700

    fix whats-new merge.

commit 4489394
Merge: 279ff1d b74f80c
Author: dcherian <[email protected]>
Date:   Wed Nov 13 08:03:06 2019 -0700

    Merge remote-tracking branch 'upstream/master' into fix/plot-broadcast

    * upstream/master:
      format indexing.rst code with black (pydata#3511)
      add missing pint integration tests (pydata#3508)
      DOC: update bottleneck repo url (pydata#3507)
      add drop_sel, drop_vars, map to api.rst (pydata#3506)
      remove syntax warning (pydata#3505)
      Dataset.map, GroupBy.map, Resample.map (pydata#3459)
      tests for datasets with units (pydata#3447)
      fix pandas-dev tests (pydata#3491)
      unpin pseudonetcdf (pydata#3496)
      whatsnew corrections (pydata#3494)
      drop_vars; deprecate drop for variables (pydata#3475)
      uamiv test using only raw uamiv variables (pydata#3485)
      Optimize dask array equality checks. (pydata#3453)
      Propagate indexes in DataArray binary operations. (pydata#3481)
      python 3.8 tests (pydata#3477)

commit 279ff1d
Author: dcherian <[email protected]>
Date:   Wed Nov 13 08:02:44 2019 -0700

    Undo the transpose change and add test to make sure transposition is right.

commit c9cc698
Author: dcherian <[email protected]>
Date:   Wed Nov 13 08:01:39 2019 -0700

    Test to make sure transpose is right

commit 9b35ecf
Author: dcherian <[email protected]>
Date:   Sat Nov 2 15:49:08 2019 -0600

    Additional test.

commit 7aed950
Author: dcherian <[email protected]>
Date:   Sat Nov 2 15:20:07 2019 -0600

    make plotting work with transposed nondim coords.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants