From cfd2c071cf8df984e5bc4c673abc84e17882d323 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Thu, 25 Nov 2021 21:02:44 -0700 Subject: [PATCH] minimize conflicts --- xarray/util/generate_reductions.py | 37 ++++++++++-------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/xarray/util/generate_reductions.py b/xarray/util/generate_reductions.py index c25c0605a11..5d4aa2145e1 100644 --- a/xarray/util/generate_reductions.py +++ b/xarray/util/generate_reductions.py @@ -20,19 +20,16 @@ """Mixin classes with reduction operations.""" # This file was generated using xarray.util.generate_reductions. Do not edit manually. -import sys -from typing import Any, Callable, Hashable, Optional, Sequence, Union +from typing import TYPE_CHECKING, Any, Callable, Hashable, Optional, Sequence, Union from . import duck_array_ops from .options import OPTIONS from .types import T_DataArray, T_Dataset from .utils import contains_only_dask_or_numpy -if sys.version_info >= (3, 8): - from typing import Protocol -else: - from typing_extensions import Protocol - +if TYPE_CHECKING: + from .dataarray import DataArray + from .dataset import Dataset try: import flox @@ -41,7 +38,7 @@ OBJ_PREAMBLE = """ -class {obj}Reduce(Protocol): +class {obj}Reductions(): def reduce( self, func: Callable[..., Any], @@ -50,12 +47,12 @@ def reduce( keep_attrs: bool = None, keepdims: bool = False, **kwargs: Any, - ) -> T_{obj}: + ) -> "{obj}": ... -class {obj}GroupByReduce(Protocol): - _obj: T_{obj} +class {obj}GroupByReductions(): + _obj: "{obj}" def reduce( self, @@ -65,14 +62,14 @@ def reduce( keep_attrs: bool = None, keepdims: bool = False, **kwargs: Any, - ) -> T_{obj}: + ) -> "{obj}": ... def _flox_reduce( self, dim: Union[None, Hashable, Sequence[Hashable]], **kwargs, - ) -> T_{obj}: + ) -> "{obj}": ...""" @@ -83,11 +80,11 @@ class {obj}{cls}Reductions: TEMPLATE_REDUCTION_SIGNATURE = ''' def {method}( - self: {self_type}, + self, dim: Union[None, Hashable, Sequence[Hashable]] = None,{extra_kwargs} keep_attrs: bool = None, **kwargs, - ) -> T_{obj}: + ) -> "{obj}": """ Reduce this {obj}'s data by applying ``{method}`` along some dimension(s). @@ -212,7 +209,6 @@ def __init__( self, cls, datastructure, - self_type, methods, docref, docref_description, @@ -220,7 +216,6 @@ def __init__( see_also_obj=None, ): self.datastructure = datastructure - self.self_type = self_type self.cls = cls self.methods = methods self.docref = docref @@ -420,7 +415,6 @@ class DataStructure: docref_description="reduction or aggregation operations", example_call_preamble="", see_also_obj="DataArray", - self_type="DatasetReduce", ) DataArrayGenerator = GenericReductionGenerator( cls="", @@ -430,7 +424,6 @@ class DataStructure: docref_description="reduction or aggregation operations", example_call_preamble="", see_also_obj="Dataset", - self_type="DataArrayReduce", ) DataArrayGroupByGenerator = GroupByReductionGenerator( @@ -440,7 +433,6 @@ class DataStructure: docref="groupby", docref_description="groupby operations", example_call_preamble='.groupby("labels")', - self_type="DataArrayGroupByReduce", ) DataArrayResampleGenerator = GroupByReductionGenerator( cls="Resample", @@ -449,7 +441,6 @@ class DataStructure: docref="resampling", docref_description="resampling operations", example_call_preamble='.resample(time="3M")', - self_type="DataArrayGroupByReduce", ) DatasetGroupByGenerator = GroupByReductionGenerator( cls="GroupBy", @@ -458,7 +449,6 @@ class DataStructure: docref="groupby", docref_description="groupby operations", example_call_preamble='.groupby("labels")', - self_type="DatasetGroupByReduce", ) DatasetResampleGenerator = GroupByReductionGenerator( cls="Resample", @@ -467,14 +457,11 @@ class DataStructure: docref="resampling", docref_description="resampling operations", example_call_preamble='.resample(time="3M")', - self_type="DatasetGroupByReduce", ) if __name__ == "__main__": print(MODULE_PREAMBLE) - print(OBJ_PREAMBLE.format(obj="Dataset")) - print(OBJ_PREAMBLE.format(obj="DataArray")) for gen in [ DatasetGenerator, DataArrayGenerator,