-
-
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
Future warning for default reduction dimension of groupby #2366
Changes from 2 commits
ba96852
fca0425
b5d94c0
cd16cb7
1df4463
604d296
f6182ea
f80bdf2
daafe87
917e04a
2c1e1ed
217c0b6
e7b7362
68d7c04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,5 @@ | |
from . import tutorial | ||
from . import ufuncs | ||
from . import testing | ||
|
||
from .core.common import ALL_DIMS |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,8 @@ | |
from .. import conventions | ||
from .alignment import align | ||
from .common import ( | ||
DataWithCoords, ImplementsDatasetReduce, _contains_datetime_like_objects) | ||
ALL_DIMS, DataWithCoords, ImplementsDatasetReduce, | ||
_contains_datetime_like_objects) | ||
from .coordinates import ( | ||
DatasetCoordinates, Indexes, LevelCoordinatesSource, | ||
assert_coordinate_consistent, remap_label_indexers) | ||
|
@@ -2722,8 +2723,8 @@ def combine_first(self, other): | |
out = ops.fillna(self, other, join="outer", dataset_join="outer") | ||
return out | ||
|
||
def reduce(self, func, dim=None, keep_attrs=False, numeric_only=False, | ||
allow_lazy=False, **kwargs): | ||
def reduce(self, func, dim=None, keep_attrs=False, | ||
numeric_only=False, allow_lazy=False, **kwargs): | ||
"""Reduce this dataset by applying `func` along some dimension(s). | ||
|
||
Parameters | ||
|
@@ -2750,6 +2751,8 @@ def reduce(self, func, dim=None, keep_attrs=False, numeric_only=False, | |
Dataset with this object's DataArrays replaced with new DataArrays | ||
of summarized data and the indicated dimension(s) removed. | ||
""" | ||
if dim == ALL_DIMS: | ||
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. I usually prefer using |
||
dim = None | ||
if isinstance(dim, basestring): | ||
dims = set([dim]) | ||
elif dim is None: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
import functools | ||
import warnings | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
from . import dtypes, duck_array_ops, nputils, ops | ||
from . import dtypes, duck_array_ops, nputils, ops, utils | ||
from .arithmetic import SupportsArithmetic | ||
from .combine import concat | ||
from .common import ImplementsArrayReduce, ImplementsDatasetReduce | ||
from .common import ALL_DIMS, ImplementsArrayReduce, ImplementsDatasetReduce | ||
from .pycompat import integer_types, range, zip | ||
from .utils import hashable, maybe_wrap_array, peek_at, safe_cast_to_index | ||
from .variable import IndexVariable, Variable, as_variable | ||
|
@@ -567,10 +568,40 @@ def reduce(self, func, dim=None, axis=None, keep_attrs=False, | |
Array with summarized data and the indicated dimension(s) | ||
removed. | ||
""" | ||
if dim is 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. To silence warning, set " | ||
"dim=xarray.ALL_DIMS explicitly.", | ||
FutureWarning, stacklevel=2) | ||
if dim is None: # TODO enable this after the deprecation | ||
dim = self._group_dim | ||
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. I don't think we should add this yet -- this means that code that uses |
||
|
||
def reduce_array(ar): | ||
return ar.reduce(func, dim, axis, keep_attrs=keep_attrs, **kwargs) | ||
return self.apply(reduce_array, shortcut=shortcut) | ||
|
||
# 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, axis=None, skipna=None, | ||
keep_attrs=False, **kwargs): | ||
return self.reduce(func, dim, axis, keep_attrs=keep_attrs, | ||
skipna=skipna, allow_lazy=True, **kwargs) | ||
else: | ||
def wrapped_func(self, dim=DEFAULT_DIMS, axis=None, keep_attrs=False, | ||
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. E501 line too long (81 > 79 characters) |
||
**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) | ||
|
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.
F401 '.common.ALL_DIMS' imported but unused