diff --git a/xarray/core/groupby.py b/xarray/core/groupby.py index 73ce9c3c53f..5c55ec7b600 100644 --- a/xarray/core/groupby.py +++ b/xarray/core/groupby.py @@ -4,7 +4,7 @@ import warnings from abc import ABC, abstractmethod from collections.abc import Hashable, Iterator, Mapping, Sequence -from dataclasses import dataclass +from dataclasses import dataclass, field from typing import ( TYPE_CHECKING, Any, @@ -519,17 +519,14 @@ class UniqueGrouper(Grouper): pass -@dataclass(init=False) +@dataclass class BinGrouper(Grouper): - def __init__(self, bins, cut_kwargs: Mapping | None): - if duck_array_ops.isnull(bins).all(): - raise ValueError("All bin edges are NaN.") + bins: Any # TODO: What is the typing? + cut_kwargs: Mapping = field(default_factory=dict) - if cut_kwargs is None: - cut_kwargs = {} - - self.bins = bins - self.cut_kwargs = cut_kwargs + def __post_init__(self): + if duck_array_ops.isnull(self.bins).all(): + raise ValueError("All bin edges are NaN.") @dataclass