Skip to content

Commit

Permalink
Allow importing from xarray.groupers (#9289)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian authored Jul 29, 2024
1 parent 470d1e8 commit ea23dd9
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 25 deletions.
6 changes: 3 additions & 3 deletions doc/api-hidden.rst
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,6 @@
coding.times.CFTimedeltaCoder
coding.times.CFDatetimeCoder

core.groupers.Grouper
core.groupers.Resampler
core.groupers.EncodedGroups
groupers.Grouper
groupers.Resampler
groupers.EncodedGroups
2 changes: 1 addition & 1 deletion doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ DataArray
Grouper Objects
---------------

.. currentmodule:: xarray.core
.. currentmodule:: xarray

.. autosummary::
:toctree: generated/
Expand Down
4 changes: 2 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@
"Variable": "~xarray.Variable",
"DatasetGroupBy": "~xarray.core.groupby.DatasetGroupBy",
"DataArrayGroupBy": "~xarray.core.groupby.DataArrayGroupBy",
"Grouper": "~xarray.core.groupers.Grouper",
"Resampler": "~xarray.core.groupers.Resampler",
"Grouper": "~xarray.groupers.Grouper",
"Resampler": "~xarray.groupers.Resampler",
# objects without namespace: numpy
"ndarray": "~numpy.ndarray",
"MaskedArray": "~numpy.ma.MaskedArray",
Expand Down
3 changes: 1 addition & 2 deletions xarray/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from importlib.metadata import version as _version

from xarray import testing, tutorial
from xarray import groupers, testing, tutorial
from xarray.backends.api import (
load_dataarray,
load_dataset,
Expand All @@ -14,7 +14,6 @@
from xarray.coding.cftimeindex import CFTimeIndex
from xarray.coding.frequencies import infer_freq
from xarray.conventions import SerializationWarning, decode_cf
from xarray.core import groupers
from xarray.core.alignment import align, broadcast
from xarray.core.combine import combine_by_coords, combine_nested
from xarray.core.common import ALL_DIMS, full_like, ones_like, zeros_like
Expand Down
4 changes: 2 additions & 2 deletions xarray/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

from xarray.core.dataarray import DataArray
from xarray.core.dataset import Dataset
from xarray.core.groupers import Resampler
from xarray.core.indexes import Index
from xarray.core.resample import Resample
from xarray.core.rolling_exp import RollingExp
Expand All @@ -53,6 +52,7 @@
T_Variable,
)
from xarray.core.variable import Variable
from xarray.groupers import Resampler

DTypeMaybeMapping = Union[DTypeLikeSave, Mapping[Any, DTypeLikeSave]]

Expand Down Expand Up @@ -1048,8 +1048,8 @@ def _resample(

from xarray.core.dataarray import DataArray
from xarray.core.groupby import ResolvedGrouper
from xarray.core.groupers import Resampler, TimeResampler
from xarray.core.resample import RESAMPLE_DIM
from xarray.groupers import Resampler, TimeResampler

indexer = either_dict_or_kwargs(indexer, indexer_kwargs, "resample")
if len(indexer) != 1:
Expand Down
6 changes: 3 additions & 3 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
from xarray.backends import ZarrStore
from xarray.backends.api import T_NetcdfEngine, T_NetcdfTypes
from xarray.core.groupby import DataArrayGroupBy
from xarray.core.groupers import Grouper, Resampler
from xarray.core.resample import DataArrayResample
from xarray.core.rolling import DataArrayCoarsen, DataArrayRolling
from xarray.core.types import (
Expand All @@ -112,6 +111,7 @@
T_Xarray,
)
from xarray.core.weighted import DataArrayWeighted
from xarray.groupers import Grouper, Resampler
from xarray.namedarray.parallelcompat import ChunkManagerEntrypoint

T_XarrayOther = TypeVar("T_XarrayOther", bound=Union["DataArray", Dataset])
Expand Down Expand Up @@ -6788,7 +6788,7 @@ def groupby(
ResolvedGrouper,
_validate_groupby_squeeze,
)
from xarray.core.groupers import UniqueGrouper
from xarray.groupers import UniqueGrouper

_validate_groupby_squeeze(squeeze)

Expand Down Expand Up @@ -6893,7 +6893,7 @@ def groupby_bins(
ResolvedGrouper,
_validate_groupby_squeeze,
)
from xarray.core.groupers import BinGrouper
from xarray.groupers import BinGrouper

_validate_groupby_squeeze(squeeze)
grouper = BinGrouper(
Expand Down
8 changes: 4 additions & 4 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@
from xarray.backends.api import T_NetcdfEngine, T_NetcdfTypes
from xarray.core.dataarray import DataArray
from xarray.core.groupby import DatasetGroupBy
from xarray.core.groupers import Grouper, Resampler
from xarray.core.merge import CoercibleMapping, CoercibleValue, _MergeResult
from xarray.core.resample import DatasetResample
from xarray.core.rolling import DatasetCoarsen, DatasetRolling
Expand Down Expand Up @@ -166,6 +165,7 @@
T_Xarray,
)
from xarray.core.weighted import DatasetWeighted
from xarray.groupers import Grouper, Resampler
from xarray.namedarray.parallelcompat import ChunkManagerEntrypoint


Expand Down Expand Up @@ -2709,7 +2709,7 @@ def chunk(
dask.array.from_array
"""
from xarray.core.dataarray import DataArray
from xarray.core.groupers import TimeResampler
from xarray.groupers import TimeResampler

if chunks is None and not chunks_kwargs:
warnings.warn(
Expand Down Expand Up @@ -10370,7 +10370,7 @@ def groupby(
ResolvedGrouper,
_validate_groupby_squeeze,
)
from xarray.core.groupers import UniqueGrouper
from xarray.groupers import UniqueGrouper

_validate_groupby_squeeze(squeeze)

Expand Down Expand Up @@ -10473,7 +10473,7 @@ def groupby_bins(
ResolvedGrouper,
_validate_groupby_squeeze,
)
from xarray.core.groupers import BinGrouper
from xarray.groupers import BinGrouper

_validate_groupby_squeeze(squeeze)
grouper = BinGrouper(
Expand Down
8 changes: 4 additions & 4 deletions xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@

from xarray.core.dataarray import DataArray
from xarray.core.dataset import Dataset
from xarray.core.groupers import Grouper
from xarray.core.types import GroupIndex, GroupIndices, GroupKey
from xarray.core.utils import Frozen
from xarray.groupers import Grouper


def check_reduce_dims(reduce_dims, dimensions):
Expand Down Expand Up @@ -581,7 +581,7 @@ def _iter_grouped(self) -> Iterator[T_Xarray]:
yield self._obj.isel({self._group_dim: indices})

def _infer_concat_args(self, applied_example):
from xarray.core.groupers import BinGrouper
from xarray.groupers import BinGrouper

(grouper,) = self.groupers
if self._group_dim in applied_example.dims:
Expand Down Expand Up @@ -695,7 +695,7 @@ def _maybe_restore_empty_groups(self, combined):
"""Our index contained empty groups (e.g., from a resampling or binning). If we
reduced on that dimension, we want to restore the full index.
"""
from xarray.core.groupers import BinGrouper, TimeResampler
from xarray.groupers import BinGrouper, TimeResampler

(grouper,) = self.groupers
if (
Expand Down Expand Up @@ -731,7 +731,7 @@ def _flox_reduce(
from flox.xarray import xarray_reduce

from xarray.core.dataset import Dataset
from xarray.core.groupers import BinGrouper
from xarray.groupers import BinGrouper

obj = self._original_obj
(grouper,) = self.groupers
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from xarray.core.dataarray import DataArray
from xarray.core.dataset import Dataset

from xarray.core.groupers import RESAMPLE_DIM
from xarray.groupers import RESAMPLE_DIM


class Resample(GroupBy[T_Xarray]):
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
from xarray.core.coordinates import Coordinates
from xarray.core.dataarray import DataArray
from xarray.core.dataset import Dataset
from xarray.core.groupers import TimeResampler
from xarray.core.indexes import Index, Indexes
from xarray.core.utils import Frozen
from xarray.core.variable import Variable
from xarray.groupers import TimeResampler

try:
from dask.array import Array as DaskArray
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
from xarray.core import dtypes, indexing, utils
from xarray.core.common import duck_array_ops, full_like
from xarray.core.coordinates import Coordinates, DatasetCoordinates
from xarray.core.groupers import TimeResampler
from xarray.core.indexes import Index, PandasIndex
from xarray.core.types import ArrayLike
from xarray.core.utils import is_scalar
from xarray.groupers import TimeResampler
from xarray.namedarray.pycompat import array_type, integer_types
from xarray.testing import _assert_internal_invariants
from xarray.tests import (
Expand Down
2 changes: 1 addition & 1 deletion xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import xarray as xr
from xarray import DataArray, Dataset, Variable
from xarray.core.groupby import _consolidate_slices
from xarray.core.groupers import BinGrouper, EncodedGroups, Grouper, UniqueGrouper
from xarray.core.types import InterpOptions
from xarray.groupers import BinGrouper, EncodedGroups, Grouper, UniqueGrouper
from xarray.tests import (
InaccessibleArray,
assert_allclose,
Expand Down

0 comments on commit ea23dd9

Please sign in to comment.