-
-
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
Deprecation: groupby, resample default dim. #3313
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,9 @@ | |
import numpy as np | ||
import pandas as pd | ||
|
||
from . import dtypes, duck_array_ops, nputils, ops, utils | ||
from . import dtypes, duck_array_ops, nputils, ops | ||
from .arithmetic import SupportsArithmetic | ||
from .common import ALL_DIMS, ImplementsArrayReduce, ImplementsDatasetReduce | ||
from .common import ImplementsArrayReduce, ImplementsDatasetReduce | ||
from .concat import concat | ||
from .options import _get_keep_attrs | ||
from .pycompat import integer_types | ||
|
@@ -700,19 +700,8 @@ def quantile(self, q, dim=None, interpolation="linear", keep_attrs=None): | |
numpy.nanpercentile, pandas.Series.quantile, Dataset.quantile, | ||
DataArray.quantile | ||
""" | ||
if dim == DEFAULT_DIMS: | ||
dim = ALL_DIMS | ||
# TODO change this to dim = self._group_dim after | ||
# the deprecation process | ||
if self._obj.ndim > 1: | ||
warnings.warn( | ||
"Default reduction dimension will be changed to the " | ||
"grouped dimension in a future version of xarray. To " | ||
"silence this warning, pass dim=xarray.ALL_DIMS " | ||
"explicitly.", | ||
FutureWarning, | ||
stacklevel=2, | ||
) | ||
if dim is None: | ||
dim = self._group_dim | ||
|
||
out = self.apply( | ||
self._obj.__class__.quantile, | ||
|
@@ -758,20 +747,6 @@ def reduce( | |
Array with summarized data and the indicated dimension(s) | ||
removed. | ||
""" | ||
if dim == DEFAULT_DIMS: | ||
dim = ALL_DIMS | ||
# TODO change this to dim = self._group_dim after | ||
# the deprecation process | ||
if self._obj.ndim > 1: | ||
warnings.warn( | ||
"Default reduction dimension will be changed to the " | ||
"grouped dimension in a future version of xarray. To " | ||
"silence this warning, pass dim=xarray.ALL_DIMS " | ||
"explicitly.", | ||
FutureWarning, | ||
stacklevel=2, | ||
) | ||
|
||
if keep_attrs is None: | ||
keep_attrs = _get_keep_attrs(default=False) | ||
|
||
|
@@ -780,43 +755,6 @@ def reduce_array(ar): | |
|
||
return self.apply(reduce_array, shortcut=shortcut) | ||
|
||
# TODO remove the following class method and DEFAULT_DIMS after the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blindly followed instructions here... |
||
# deprecation cycle | ||
@classmethod | ||
def _reduce_method(cls, func, include_skipna, numeric_only): | ||
if include_skipna: | ||
|
||
def wrapped_func( | ||
self, | ||
dim=DEFAULT_DIMS, | ||
axis=None, | ||
skipna=None, | ||
keep_attrs=None, | ||
**kwargs | ||
): | ||
return self.reduce( | ||
func, | ||
dim, | ||
axis, | ||
keep_attrs=keep_attrs, | ||
skipna=skipna, | ||
allow_lazy=True, | ||
**kwargs | ||
) | ||
|
||
else: | ||
|
||
def wrapped_func( # type: ignore | ||
self, dim=DEFAULT_DIMS, axis=None, keep_attrs=None, **kwargs | ||
): | ||
return self.reduce( | ||
func, dim, axis, keep_attrs=keep_attrs, allow_lazy=True, **kwargs | ||
) | ||
|
||
return wrapped_func | ||
|
||
|
||
DEFAULT_DIMS = utils.ReprObject("<default-dims>") | ||
|
||
ops.inject_reduce_methods(DataArrayGroupBy) | ||
ops.inject_binary_ops(DataArrayGroupBy) | ||
|
@@ -898,19 +836,7 @@ def reduce(self, func, dim=None, keep_attrs=None, **kwargs): | |
Array with summarized data and the indicated dimension(s) | ||
removed. | ||
""" | ||
if dim == DEFAULT_DIMS: | ||
dim = ALL_DIMS | ||
# TODO change this to dim = self._group_dim after | ||
# the deprecation process. Do not forget to remove _reduce_method | ||
warnings.warn( | ||
"Default reduction dimension will be changed to the " | ||
"grouped dimension in a future version of xarray. To " | ||
"silence this warning, pass dim=xarray.ALL_DIMS " | ||
"explicitly.", | ||
FutureWarning, | ||
stacklevel=2, | ||
) | ||
elif dim is None: | ||
if dim is None: | ||
dim = self._group_dim | ||
|
||
if keep_attrs is None: | ||
|
@@ -921,31 +847,6 @@ def reduce_dataset(ds): | |
|
||
return self.apply(reduce_dataset) | ||
|
||
# TODO remove the following class method and DEFAULT_DIMS after the | ||
# deprecation cycle | ||
@classmethod | ||
def _reduce_method(cls, func, include_skipna, numeric_only): | ||
if include_skipna: | ||
|
||
def wrapped_func(self, dim=DEFAULT_DIMS, skipna=None, **kwargs): | ||
return self.reduce( | ||
func, | ||
dim, | ||
skipna=skipna, | ||
numeric_only=numeric_only, | ||
allow_lazy=True, | ||
**kwargs | ||
) | ||
|
||
else: | ||
|
||
def wrapped_func(self, dim=DEFAULT_DIMS, **kwargs): # type: ignore | ||
return self.reduce( | ||
func, dim, numeric_only=numeric_only, allow_lazy=True, **kwargs | ||
) | ||
|
||
return wrapped_func | ||
|
||
def assign(self, **kwargs): | ||
"""Assign data variables by group. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
the two changes in this file are minor unrelated cleanups.