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

Deprecate inplace #2524

Merged
merged 10 commits into from
Nov 3, 2018
Merged

Deprecate inplace #2524

merged 10 commits into from
Nov 3, 2018

Conversation

dcherian
Copy link
Contributor

@dcherian dcherian commented Oct 29, 2018

  • Closes Deprecate inplace methods #1756 (remove if there is no corresponding issue, which should only be the case for minor changes)
  • Tests added (for all bug fixes or enhancements)
  • Fully documented, including whats-new.rst for all changes and api.rst for new API (remove if this change should not be visible to users, e.g., if it is an internal clean-up, or if this is part of a larger project that will be documented later)

@pep8speaks
Copy link

Hello @dcherian! Thanks for submitting the PR.

@@ -2494,12 +2501,13 @@ def update(self, other, inplace=True):
If any dimensions would have inconsistent sizes in the updated
dataset.
"""
# _check_inplace(inplace)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shoyer What's the right thing to do here? Changing the default to None/False breaks a lot of test.

Copy link
Member

Choose a reason for hiding this comment

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

Dataset.update() has always been an in-place operation for consistency with dict.update(). I don't think it really makes sense to change that.

I would suggest that we do the deprecation the other direction here: remove the inplace argument but keep the behavior as always inplace.

inplace = default
else:
warnings.warn('The inplace argument has been deprecated and will be '
'removed in xarray 0.12.0.', FutureWarning)
Copy link
Member

Choose a reason for hiding this comment

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

Can you add the stacklevel argument with an appropriate value? (you'll need to experiment a bit)

That ensures that warnings end up pointing to the specific line of code that need to be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

stacklevel=3 seems to give useful warnings with the test suite

xarray/tests/test_dataset.py::TestDataset::()::test_expand_dims_error
  /home/deepak/work/python/xarray/xarray/tests/test_dataset.py:2016: FutureWarning: The inplace argument has been deprecated and will be removed in xarray 0.12.0.
    original.set_coords('z', inplace=True)

dcherian added 2 commits October 30, 2018 10:14
* master:
  Global option to always keep/discard attrs on operations (pydata#2482)
  Remove tests where answers change in cftime 1.0.2.1 (pydata#2522)
  Finish deprecation cycle for DataArray.__contains__ checking array values (pydata#2520)
  Fix bug where OverflowError is not being raised (pydata#2519)
@dcherian
Copy link
Contributor Author

Failed test is dask distributed test

@@ -23,6 +23,7 @@
requires_scipy, source_ndarray)


@pytest.mark.filterwarnings('ignore:The inplace argument')
Copy link
Member

Choose a reason for hiding this comment

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

Can we try fixing these tests now instead? Otherwise we may be stuck with large clean-up later.

For testing deprecations, I find it often helps to convert warnings into an error, e.g., by adding raise Exception on the line after issuing the warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought we might want to keep those tests around while people are still using that code path.

Copy link
Member

Choose a reason for hiding this comment

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

I forgot the main reason for doing this: to make sure that xarray doesn't rely upon the deprecated behavior internally.

But if you already checked that, then I suppose this is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I haven't checked that closely but I can do that tonight.
(my impression was that the tests were testing inplace behaviour, but I see that could be wrong)

@shoyer
Copy link
Member

shoyer commented Oct 30, 2018 via email

@dcherian
Copy link
Contributor Author

OK so what's left is Dataset._calculate_binary_op(g, other, inplace=True) called by Dataset._inplace_binary_op at Line 3307 in dataset.py. I don't know what the right fix is.

@shoyer
Copy link
Member

shoyer commented Nov 1, 2018 via email

@shoyer shoyer merged commit 848d491 into pydata:master Nov 3, 2018
@shoyer
Copy link
Member

shoyer commented Nov 3, 2018

thanks @dcherian

dcherian pushed a commit to yohai/xarray that referenced this pull request Dec 16, 2018
* upstream/master: (122 commits)
  add missing , and article in error message (pydata#2557)
  Add libnetcdf, libhdf5, pydap and cfgrib to xarray.show_versions() (pydata#2555)
  revert to dev version for 0.11.1
  Release xarray v0.11
  DOC: update whatsnew for xarray 0.11 release (pydata#2548)
  Drop the hack needed to use CachingFileManager as we don't use it anymore. (pydata#2544)
  add full test env for py37 ci env (pydata#2545)
  Remove old-style resample example in documentation (pydata#2543)
  Stop loading tutorial data by default (pydata#2538)
  Remove the old syntax for resample. (pydata#2541)
  Remove use of deprecated, unused keyword. (pydata#2540)
  Deprecate inplace (pydata#2524)
  Zarr chunking (GH2300) (pydata#2487)
  Include multidimensional stacking groupby in docs (pydata#2493) (pydata#2536)
  Switch enable_cftimeindex to True by default (pydata#2516)
  Raise more informative error when converting tuples to Variable. (pydata#2523)
  Global option to always keep/discard attrs on operations (pydata#2482)
  Remove tests where answers change in cftime 1.0.2.1 (pydata#2522)
  Finish deprecation cycle for DataArray.__contains__ checking array values (pydata#2520)
  Fix bug where OverflowError is not being raised (pydata#2519)
  ...
@dcherian dcherian deleted the deprecate/inplace branch August 15, 2019 15:33
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.

Deprecate inplace methods
3 participants