diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index deff3963d94..74d77e2f2ca 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,13 +13,13 @@ repos: - id: mixed-line-ending - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: 'v0.1.9' + rev: 'v0.2.0' hooks: - id: ruff args: ["--fix", "--show-fixes"] # https://github.com/python/black#version-control-integration - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.12.1 + rev: 24.1.1 hooks: - id: black-jupyter - repo: https://github.com/keewis/blackdoc @@ -27,7 +27,7 @@ repos: hooks: - id: blackdoc exclude: "generate_aggregations.py" - additional_dependencies: ["black==23.12.1"] + additional_dependencies: ["black==24.1.1"] - id: blackdoc-autoupdate-black - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.8.0 diff --git a/doc/contributing.rst b/doc/contributing.rst index 4db7bafb631..c3dc484f4c1 100644 --- a/doc/contributing.rst +++ b/doc/contributing.rst @@ -670,8 +670,7 @@ typically find tests wrapped in a class. .. code-block:: python - class TestReallyCoolFeature: - ... + class TestReallyCoolFeature: ... Going forward, we are moving to a more *functional* style using the `pytest `__ framework, which offers a richer @@ -680,8 +679,7 @@ writing test classes, we will write test functions like this: .. code-block:: python - def test_really_cool_feature(): - ... + def test_really_cool_feature(): ... Using ``pytest`` ~~~~~~~~~~~~~~~~ diff --git a/doc/gallery/plot_cartopy_facetgrid.py b/doc/gallery/plot_cartopy_facetgrid.py index a4ab23c42a6..faa148938d6 100644 --- a/doc/gallery/plot_cartopy_facetgrid.py +++ b/doc/gallery/plot_cartopy_facetgrid.py @@ -13,7 +13,6 @@ .. _this discussion: https://github.com/pydata/xarray/issues/1397#issuecomment-299190567 """ - import cartopy.crs as ccrs import matplotlib.pyplot as plt diff --git a/doc/gallery/plot_control_colorbar.py b/doc/gallery/plot_control_colorbar.py index 8fb8d7f8be6..280e753db9a 100644 --- a/doc/gallery/plot_control_colorbar.py +++ b/doc/gallery/plot_control_colorbar.py @@ -6,6 +6,7 @@ Use ``cbar_kwargs`` keyword to specify the number of ticks. The ``spacing`` kwarg can be used to draw proportional ticks. """ + import matplotlib.pyplot as plt import xarray as xr diff --git a/properties/test_encode_decode.py b/properties/test_encode_decode.py index 3ba037e28b0..60e1bbe81c1 100644 --- a/properties/test_encode_decode.py +++ b/properties/test_encode_decode.py @@ -4,6 +4,7 @@ These ones pass, just as you'd hope! """ + import pytest pytest.importorskip("hypothesis") diff --git a/properties/test_pandas_roundtrip.py b/properties/test_pandas_roundtrip.py index e8cef95c029..5c0f14976e6 100644 --- a/properties/test_pandas_roundtrip.py +++ b/properties/test_pandas_roundtrip.py @@ -1,6 +1,7 @@ """ Property-based tests for roundtripping between xarray and pandas objects. """ + from functools import partial import numpy as np diff --git a/xarray/backends/__init__.py b/xarray/backends/__init__.py index 0044593b4ea..1c8d2d3a659 100644 --- a/xarray/backends/__init__.py +++ b/xarray/backends/__init__.py @@ -3,6 +3,7 @@ DataStores provide a uniform interface for saving and loading data in different formats. They should not be used directly, but rather through Dataset objects. """ + from xarray.backends.common import AbstractDataStore, BackendArray, BackendEntrypoint from xarray.backends.file_manager import ( CachingFileManager, diff --git a/xarray/backends/api.py b/xarray/backends/api.py index 670a0ec6d68..346521675bc 100644 --- a/xarray/backends/api.py +++ b/xarray/backends/api.py @@ -791,13 +791,15 @@ def open_dataarray( def open_mfdataset( paths: str | NestedSequence[str | os.PathLike], chunks: T_Chunks | None = None, - concat_dim: str - | DataArray - | Index - | Sequence[str] - | Sequence[DataArray] - | Sequence[Index] - | None = None, + concat_dim: ( + str + | DataArray + | Index + | Sequence[str] + | Sequence[DataArray] + | Sequence[Index] + | None + ) = None, compat: CompatOptions = "no_conflicts", preprocess: Callable[[Dataset], Dataset] | None = None, engine: T_Engine | None = None, @@ -1101,8 +1103,7 @@ def to_netcdf( *, multifile: Literal[True], invalid_netcdf: bool = False, -) -> tuple[ArrayWriter, AbstractDataStore]: - ... +) -> tuple[ArrayWriter, AbstractDataStore]: ... # path=None writes to bytes @@ -1119,8 +1120,7 @@ def to_netcdf( compute: bool = True, multifile: Literal[False] = False, invalid_netcdf: bool = False, -) -> bytes: - ... +) -> bytes: ... # compute=False returns dask.Delayed @@ -1138,8 +1138,7 @@ def to_netcdf( compute: Literal[False], multifile: Literal[False] = False, invalid_netcdf: bool = False, -) -> Delayed: - ... +) -> Delayed: ... # default return None @@ -1156,8 +1155,7 @@ def to_netcdf( compute: Literal[True] = True, multifile: Literal[False] = False, invalid_netcdf: bool = False, -) -> None: - ... +) -> None: ... # if compute cannot be evaluated at type check time @@ -1175,8 +1173,7 @@ def to_netcdf( compute: bool = False, multifile: Literal[False] = False, invalid_netcdf: bool = False, -) -> Delayed | None: - ... +) -> Delayed | None: ... # if multifile cannot be evaluated at type check time @@ -1194,8 +1191,7 @@ def to_netcdf( compute: bool = False, multifile: bool = False, invalid_netcdf: bool = False, -) -> tuple[ArrayWriter, AbstractDataStore] | Delayed | None: - ... +) -> tuple[ArrayWriter, AbstractDataStore] | Delayed | None: ... # Any @@ -1212,8 +1208,7 @@ def to_netcdf( compute: bool = False, multifile: bool = False, invalid_netcdf: bool = False, -) -> tuple[ArrayWriter, AbstractDataStore] | bytes | Delayed | None: - ... +) -> tuple[ArrayWriter, AbstractDataStore] | bytes | Delayed | None: ... def to_netcdf( @@ -1647,8 +1642,7 @@ def to_zarr( zarr_version: int | None = None, write_empty_chunks: bool | None = None, chunkmanager_store_kwargs: dict[str, Any] | None = None, -) -> backends.ZarrStore: - ... +) -> backends.ZarrStore: ... # compute=False returns dask.Delayed @@ -1671,8 +1665,7 @@ def to_zarr( zarr_version: int | None = None, write_empty_chunks: bool | None = None, chunkmanager_store_kwargs: dict[str, Any] | None = None, -) -> Delayed: - ... +) -> Delayed: ... def to_zarr( diff --git a/xarray/backends/locks.py b/xarray/backends/locks.py index 045ee522fa8..69cef309b45 100644 --- a/xarray/backends/locks.py +++ b/xarray/backends/locks.py @@ -40,9 +40,9 @@ class SerializableLock: The creation of locks is itself not threadsafe. """ - _locks: ClassVar[ - WeakValueDictionary[Hashable, threading.Lock] - ] = WeakValueDictionary() + _locks: ClassVar[WeakValueDictionary[Hashable, threading.Lock]] = ( + WeakValueDictionary() + ) token: Hashable lock: threading.Lock diff --git a/xarray/coding/cftime_offsets.py b/xarray/coding/cftime_offsets.py index 7da00c4dd6c..baba13f2703 100644 --- a/xarray/coding/cftime_offsets.py +++ b/xarray/coding/cftime_offsets.py @@ -1,4 +1,5 @@ """Time offset classes for use with cftime.datetime objects""" + # The offset classes and mechanisms for generating time ranges defined in # this module were copied/adapted from those defined in pandas. See in # particular the objects and methods defined in pandas.tseries.offsets diff --git a/xarray/coding/cftimeindex.py b/xarray/coding/cftimeindex.py index bddcea97787..a4d8428d1b1 100644 --- a/xarray/coding/cftimeindex.py +++ b/xarray/coding/cftimeindex.py @@ -1,4 +1,5 @@ """DatetimeIndex analog for cftime.datetime objects""" + # The pandas.Index subclass defined here was copied and adapted for # use with cftime.datetime objects based on the source code defining # pandas.DatetimeIndex. diff --git a/xarray/coding/frequencies.py b/xarray/coding/frequencies.py index 341627ab114..5ae1d8b1bab 100644 --- a/xarray/coding/frequencies.py +++ b/xarray/coding/frequencies.py @@ -1,4 +1,5 @@ """FrequencyInferer analog for cftime.datetime objects""" + # The infer_freq method and the _CFTimeFrequencyInferer # subclass defined here were copied and adapted for # use with cftime.datetime objects based on the source code in diff --git a/xarray/coding/strings.py b/xarray/coding/strings.py index fa57bffb8d5..07665230b26 100644 --- a/xarray/coding/strings.py +++ b/xarray/coding/strings.py @@ -1,4 +1,5 @@ """Coders for strings.""" + from __future__ import annotations from functools import partial diff --git a/xarray/coding/variables.py b/xarray/coding/variables.py index c3d57ad1903..3d70b39d03f 100644 --- a/xarray/coding/variables.py +++ b/xarray/coding/variables.py @@ -1,4 +1,5 @@ """Coders for individual Variable objects.""" + from __future__ import annotations import warnings diff --git a/xarray/convert.py b/xarray/convert.py index aeb746f4a9c..404a279f1f8 100644 --- a/xarray/convert.py +++ b/xarray/convert.py @@ -1,5 +1,6 @@ """Functions for converting to and from xarray objects """ + from collections import Counter import numpy as np diff --git a/xarray/core/_aggregations.py b/xarray/core/_aggregations.py index e214c2c7c5a..3756091f91f 100644 --- a/xarray/core/_aggregations.py +++ b/xarray/core/_aggregations.py @@ -1,4 +1,5 @@ """Mixin classes with reduction operations.""" + # This file was generated using xarray.util.generate_aggregations. Do not edit manually. from __future__ import annotations diff --git a/xarray/core/_typed_ops.py b/xarray/core/_typed_ops.py index ceab91ad991..c1748e322c2 100644 --- a/xarray/core/_typed_ops.py +++ b/xarray/core/_typed_ops.py @@ -1,4 +1,5 @@ """Mixin classes with arithmetic operators.""" + # This file was generated using xarray.util.generate_ops. Do not edit manually. from __future__ import annotations @@ -454,199 +455,163 @@ def _binary_op( raise NotImplementedError @overload - def __add__(self, other: T_DataArray) -> T_DataArray: - ... + def __add__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __add__(self, other: VarCompatible) -> Self: - ... + def __add__(self, other: VarCompatible) -> Self: ... def __add__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, operator.add) @overload - def __sub__(self, other: T_DataArray) -> T_DataArray: - ... + def __sub__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __sub__(self, other: VarCompatible) -> Self: - ... + def __sub__(self, other: VarCompatible) -> Self: ... def __sub__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, operator.sub) @overload - def __mul__(self, other: T_DataArray) -> T_DataArray: - ... + def __mul__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __mul__(self, other: VarCompatible) -> Self: - ... + def __mul__(self, other: VarCompatible) -> Self: ... def __mul__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, operator.mul) @overload - def __pow__(self, other: T_DataArray) -> T_DataArray: - ... + def __pow__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __pow__(self, other: VarCompatible) -> Self: - ... + def __pow__(self, other: VarCompatible) -> Self: ... def __pow__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, operator.pow) @overload - def __truediv__(self, other: T_DataArray) -> T_DataArray: - ... + def __truediv__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __truediv__(self, other: VarCompatible) -> Self: - ... + def __truediv__(self, other: VarCompatible) -> Self: ... def __truediv__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, operator.truediv) @overload - def __floordiv__(self, other: T_DataArray) -> T_DataArray: - ... + def __floordiv__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __floordiv__(self, other: VarCompatible) -> Self: - ... + def __floordiv__(self, other: VarCompatible) -> Self: ... def __floordiv__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, operator.floordiv) @overload - def __mod__(self, other: T_DataArray) -> T_DataArray: - ... + def __mod__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __mod__(self, other: VarCompatible) -> Self: - ... + def __mod__(self, other: VarCompatible) -> Self: ... def __mod__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, operator.mod) @overload - def __and__(self, other: T_DataArray) -> T_DataArray: - ... + def __and__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __and__(self, other: VarCompatible) -> Self: - ... + def __and__(self, other: VarCompatible) -> Self: ... def __and__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, operator.and_) @overload - def __xor__(self, other: T_DataArray) -> T_DataArray: - ... + def __xor__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __xor__(self, other: VarCompatible) -> Self: - ... + def __xor__(self, other: VarCompatible) -> Self: ... def __xor__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, operator.xor) @overload - def __or__(self, other: T_DataArray) -> T_DataArray: - ... + def __or__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __or__(self, other: VarCompatible) -> Self: - ... + def __or__(self, other: VarCompatible) -> Self: ... def __or__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, operator.or_) @overload - def __lshift__(self, other: T_DataArray) -> T_DataArray: - ... + def __lshift__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __lshift__(self, other: VarCompatible) -> Self: - ... + def __lshift__(self, other: VarCompatible) -> Self: ... def __lshift__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, operator.lshift) @overload - def __rshift__(self, other: T_DataArray) -> T_DataArray: - ... + def __rshift__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __rshift__(self, other: VarCompatible) -> Self: - ... + def __rshift__(self, other: VarCompatible) -> Self: ... def __rshift__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, operator.rshift) @overload - def __lt__(self, other: T_DataArray) -> T_DataArray: - ... + def __lt__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __lt__(self, other: VarCompatible) -> Self: - ... + def __lt__(self, other: VarCompatible) -> Self: ... def __lt__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, operator.lt) @overload - def __le__(self, other: T_DataArray) -> T_DataArray: - ... + def __le__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __le__(self, other: VarCompatible) -> Self: - ... + def __le__(self, other: VarCompatible) -> Self: ... def __le__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, operator.le) @overload - def __gt__(self, other: T_DataArray) -> T_DataArray: - ... + def __gt__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __gt__(self, other: VarCompatible) -> Self: - ... + def __gt__(self, other: VarCompatible) -> Self: ... def __gt__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, operator.gt) @overload - def __ge__(self, other: T_DataArray) -> T_DataArray: - ... + def __ge__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __ge__(self, other: VarCompatible) -> Self: - ... + def __ge__(self, other: VarCompatible) -> Self: ... def __ge__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, operator.ge) @overload # type:ignore[override] - def __eq__(self, other: T_DataArray) -> T_DataArray: - ... + def __eq__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __eq__(self, other: VarCompatible) -> Self: - ... + def __eq__(self, other: VarCompatible) -> Self: ... def __eq__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, nputils.array_eq) @overload # type:ignore[override] - def __ne__(self, other: T_DataArray) -> T_DataArray: - ... + def __ne__(self, other: T_DataArray) -> T_DataArray: ... @overload - def __ne__(self, other: VarCompatible) -> Self: - ... + def __ne__(self, other: VarCompatible) -> Self: ... def __ne__(self, other: VarCompatible) -> Self | T_DataArray: return self._binary_op(other, nputils.array_ne) diff --git a/xarray/core/alignment.py b/xarray/core/alignment.py index 28857c2d26e..dab3f721c0f 100644 --- a/xarray/core/alignment.py +++ b/xarray/core/alignment.py @@ -599,8 +599,7 @@ def align( indexes=None, exclude: str | Iterable[Hashable] = frozenset(), fill_value=dtypes.NA, -) -> tuple[T_Obj1]: - ... +) -> tuple[T_Obj1]: ... @overload @@ -614,8 +613,7 @@ def align( indexes=None, exclude: str | Iterable[Hashable] = frozenset(), fill_value=dtypes.NA, -) -> tuple[T_Obj1, T_Obj2]: - ... +) -> tuple[T_Obj1, T_Obj2]: ... @overload @@ -630,8 +628,7 @@ def align( indexes=None, exclude: str | Iterable[Hashable] = frozenset(), fill_value=dtypes.NA, -) -> tuple[T_Obj1, T_Obj2, T_Obj3]: - ... +) -> tuple[T_Obj1, T_Obj2, T_Obj3]: ... @overload @@ -647,8 +644,7 @@ def align( indexes=None, exclude: str | Iterable[Hashable] = frozenset(), fill_value=dtypes.NA, -) -> tuple[T_Obj1, T_Obj2, T_Obj3, T_Obj4]: - ... +) -> tuple[T_Obj1, T_Obj2, T_Obj3, T_Obj4]: ... @overload @@ -665,8 +661,7 @@ def align( indexes=None, exclude: str | Iterable[Hashable] = frozenset(), fill_value=dtypes.NA, -) -> tuple[T_Obj1, T_Obj2, T_Obj3, T_Obj4, T_Obj5]: - ... +) -> tuple[T_Obj1, T_Obj2, T_Obj3, T_Obj4, T_Obj5]: ... @overload @@ -677,8 +672,7 @@ def align( indexes=None, exclude: str | Iterable[Hashable] = frozenset(), fill_value=dtypes.NA, -) -> tuple[T_Alignable, ...]: - ... +) -> tuple[T_Alignable, ...]: ... def align( @@ -1096,15 +1090,13 @@ def _broadcast_dataset(ds: T_Dataset) -> T_Dataset: @overload def broadcast( obj1: T_Obj1, /, *, exclude: str | Iterable[Hashable] | None = None -) -> tuple[T_Obj1]: - ... +) -> tuple[T_Obj1]: ... @overload def broadcast( obj1: T_Obj1, obj2: T_Obj2, /, *, exclude: str | Iterable[Hashable] | None = None -) -> tuple[T_Obj1, T_Obj2]: - ... +) -> tuple[T_Obj1, T_Obj2]: ... @overload @@ -1115,8 +1107,7 @@ def broadcast( /, *, exclude: str | Iterable[Hashable] | None = None, -) -> tuple[T_Obj1, T_Obj2, T_Obj3]: - ... +) -> tuple[T_Obj1, T_Obj2, T_Obj3]: ... @overload @@ -1128,8 +1119,7 @@ def broadcast( /, *, exclude: str | Iterable[Hashable] | None = None, -) -> tuple[T_Obj1, T_Obj2, T_Obj3, T_Obj4]: - ... +) -> tuple[T_Obj1, T_Obj2, T_Obj3, T_Obj4]: ... @overload @@ -1142,15 +1132,13 @@ def broadcast( /, *, exclude: str | Iterable[Hashable] | None = None, -) -> tuple[T_Obj1, T_Obj2, T_Obj3, T_Obj4, T_Obj5]: - ... +) -> tuple[T_Obj1, T_Obj2, T_Obj3, T_Obj4, T_Obj5]: ... @overload def broadcast( *args: T_Alignable, exclude: str | Iterable[Hashable] | None = None -) -> tuple[T_Alignable, ...]: - ... +) -> tuple[T_Alignable, ...]: ... def broadcast( diff --git a/xarray/core/arithmetic.py b/xarray/core/arithmetic.py index d320eef1bbf..de2fbe23d35 100644 --- a/xarray/core/arithmetic.py +++ b/xarray/core/arithmetic.py @@ -1,4 +1,5 @@ """Base classes implementing arithmetic for xarray objects.""" + from __future__ import annotations import numbers diff --git a/xarray/core/combine.py b/xarray/core/combine.py index 10f194bf9f5..cfdc012dfa8 100644 --- a/xarray/core/combine.py +++ b/xarray/core/combine.py @@ -372,7 +372,7 @@ def _nested_combine( def combine_nested( datasets: DATASET_HYPERCUBE, - concat_dim: (str | DataArray | None | Sequence[str | DataArray | pd.Index | None]), + concat_dim: str | DataArray | None | Sequence[str | DataArray | pd.Index | None], compat: str = "no_conflicts", data_vars: str = "all", coords: str = "different", diff --git a/xarray/core/common.py b/xarray/core/common.py index 9f3c8eabf7b..048ec0b3488 100644 --- a/xarray/core/common.py +++ b/xarray/core/common.py @@ -200,12 +200,10 @@ def __iter__(self: Any) -> Iterator[Any]: return self._iter() @overload - def get_axis_num(self, dim: Iterable[Hashable]) -> tuple[int, ...]: - ... + def get_axis_num(self, dim: Iterable[Hashable]) -> tuple[int, ...]: ... @overload - def get_axis_num(self, dim: Hashable) -> int: - ... + def get_axis_num(self, dim: Hashable) -> int: ... def get_axis_num(self, dim: Hashable | Iterable[Hashable]) -> int | tuple[int, ...]: """Return axis number(s) corresponding to dimension(s) in this array. @@ -1443,8 +1441,7 @@ def full_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> DataArray: - ... +) -> DataArray: ... @overload @@ -1456,8 +1453,7 @@ def full_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Dataset: - ... +) -> Dataset: ... @overload @@ -1469,8 +1465,7 @@ def full_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Variable: - ... +) -> Variable: ... @overload @@ -1482,8 +1477,7 @@ def full_like( chunks: T_Chunks = {}, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Dataset | DataArray: - ... +) -> Dataset | DataArray: ... @overload @@ -1495,8 +1489,7 @@ def full_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Dataset | DataArray | Variable: - ... +) -> Dataset | DataArray | Variable: ... def full_like( @@ -1737,8 +1730,7 @@ def zeros_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> DataArray: - ... +) -> DataArray: ... @overload @@ -1749,8 +1741,7 @@ def zeros_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Dataset: - ... +) -> Dataset: ... @overload @@ -1761,8 +1752,7 @@ def zeros_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Variable: - ... +) -> Variable: ... @overload @@ -1773,8 +1763,7 @@ def zeros_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Dataset | DataArray: - ... +) -> Dataset | DataArray: ... @overload @@ -1785,8 +1774,7 @@ def zeros_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Dataset | DataArray | Variable: - ... +) -> Dataset | DataArray | Variable: ... def zeros_like( @@ -1879,8 +1867,7 @@ def ones_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> DataArray: - ... +) -> DataArray: ... @overload @@ -1891,8 +1878,7 @@ def ones_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Dataset: - ... +) -> Dataset: ... @overload @@ -1903,8 +1889,7 @@ def ones_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Variable: - ... +) -> Variable: ... @overload @@ -1915,8 +1900,7 @@ def ones_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Dataset | DataArray: - ... +) -> Dataset | DataArray: ... @overload @@ -1927,8 +1911,7 @@ def ones_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Dataset | DataArray | Variable: - ... +) -> Dataset | DataArray | Variable: ... def ones_like( diff --git a/xarray/core/computation.py b/xarray/core/computation.py index dda72c0163b..b5d1dd2ccc0 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -1,6 +1,7 @@ """ Functions for applying functions that act on arrays to xarray's labeled data. """ + from __future__ import annotations import functools @@ -731,9 +732,11 @@ def apply_variable_ufunc( output_dims = [broadcast_dims + out for out in signature.output_core_dims] input_data = [ - broadcast_compat_data(arg, broadcast_dims, core_dims) - if isinstance(arg, Variable) - else arg + ( + broadcast_compat_data(arg, broadcast_dims, core_dims) + if isinstance(arg, Variable) + else arg + ) for arg, core_dims in zip(args, signature.input_core_dims) ] @@ -2047,29 +2050,25 @@ def where(cond, x, y, keep_attrs=None): @overload def polyval( coord: DataArray, coeffs: DataArray, degree_dim: Hashable = "degree" -) -> DataArray: - ... +) -> DataArray: ... @overload def polyval( coord: DataArray, coeffs: Dataset, degree_dim: Hashable = "degree" -) -> Dataset: - ... +) -> Dataset: ... @overload def polyval( coord: Dataset, coeffs: DataArray, degree_dim: Hashable = "degree" -) -> Dataset: - ... +) -> Dataset: ... @overload def polyval( coord: Dataset, coeffs: Dataset, degree_dim: Hashable = "degree" -) -> Dataset: - ... +) -> Dataset: ... @overload @@ -2077,8 +2076,7 @@ def polyval( coord: Dataset | DataArray, coeffs: Dataset | DataArray, degree_dim: Hashable = "degree", -) -> Dataset | DataArray: - ... +) -> Dataset | DataArray: ... def polyval( @@ -2247,23 +2245,19 @@ def _calc_idxminmax( @overload -def unify_chunks(__obj: _T) -> tuple[_T]: - ... +def unify_chunks(__obj: _T) -> tuple[_T]: ... @overload -def unify_chunks(__obj1: _T, __obj2: _U) -> tuple[_T, _U]: - ... +def unify_chunks(__obj1: _T, __obj2: _U) -> tuple[_T, _U]: ... @overload -def unify_chunks(__obj1: _T, __obj2: _U, __obj3: _V) -> tuple[_T, _U, _V]: - ... +def unify_chunks(__obj1: _T, __obj2: _U, __obj3: _V) -> tuple[_T, _U, _V]: ... @overload -def unify_chunks(*objects: Dataset | DataArray) -> tuple[Dataset | DataArray, ...]: - ... +def unify_chunks(*objects: Dataset | DataArray) -> tuple[Dataset | DataArray, ...]: ... def unify_chunks(*objects: Dataset | DataArray) -> tuple[Dataset | DataArray, ...]: diff --git a/xarray/core/concat.py b/xarray/core/concat.py index 26cf36b3b07..efc1e6a414e 100644 --- a/xarray/core/concat.py +++ b/xarray/core/concat.py @@ -42,8 +42,7 @@ def concat( fill_value: object = dtypes.NA, join: JoinOptions = "outer", combine_attrs: CombineAttrsOptions = "override", -) -> T_Dataset: - ... +) -> T_Dataset: ... @overload @@ -57,8 +56,7 @@ def concat( fill_value: object = dtypes.NA, join: JoinOptions = "outer", combine_attrs: CombineAttrsOptions = "override", -) -> T_DataArray: - ... +) -> T_DataArray: ... def concat( diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 099a94592fa..b896ce658a1 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -972,8 +972,7 @@ def reset_coords( names: Dims = None, *, drop: Literal[False] = False, - ) -> Dataset: - ... + ) -> Dataset: ... @overload def reset_coords( @@ -981,8 +980,7 @@ def reset_coords( names: Dims = None, *, drop: Literal[True], - ) -> Self: - ... + ) -> Self: ... @_deprecate_positional_args("v2023.10.0") def reset_coords( @@ -3916,8 +3914,7 @@ def to_netcdf( unlimited_dims: Iterable[Hashable] | None = None, compute: bool = True, invalid_netcdf: bool = False, - ) -> bytes: - ... + ) -> bytes: ... # compute=False returns dask.Delayed @overload @@ -3933,8 +3930,7 @@ def to_netcdf( *, compute: Literal[False], invalid_netcdf: bool = False, - ) -> Delayed: - ... + ) -> Delayed: ... # default return None @overload @@ -3949,8 +3945,7 @@ def to_netcdf( unlimited_dims: Iterable[Hashable] | None = None, compute: Literal[True] = True, invalid_netcdf: bool = False, - ) -> None: - ... + ) -> None: ... # if compute cannot be evaluated at type check time # we may get back either Delayed or None @@ -3966,8 +3961,7 @@ def to_netcdf( unlimited_dims: Iterable[Hashable] | None = None, compute: bool = True, invalid_netcdf: bool = False, - ) -> Delayed | None: - ... + ) -> Delayed | None: ... def to_netcdf( self, @@ -4116,8 +4110,7 @@ def to_zarr( safe_chunks: bool = True, storage_options: dict[str, str] | None = None, zarr_version: int | None = None, - ) -> ZarrStore: - ... + ) -> ZarrStore: ... # compute=False returns dask.Delayed @overload @@ -4137,8 +4130,7 @@ def to_zarr( safe_chunks: bool = True, storage_options: dict[str, str] | None = None, zarr_version: int | None = None, - ) -> Delayed: - ... + ) -> Delayed: ... def to_zarr( self, @@ -4983,10 +4975,12 @@ def dot( def sortby( self, - variables: Hashable - | DataArray - | Sequence[Hashable | DataArray] - | Callable[[Self], Hashable | DataArray | Sequence[Hashable | DataArray]], + variables: ( + Hashable + | DataArray + | Sequence[Hashable | DataArray] + | Callable[[Self], Hashable | DataArray | Sequence[Hashable | DataArray]] + ), ascending: bool = True, ) -> Self: """Sort object by labels or values (along an axis). @@ -5596,14 +5590,12 @@ def pad( self, pad_width: Mapping[Any, int | tuple[int, int]] | None = None, mode: PadModeOptions = "constant", - stat_length: int - | tuple[int, int] - | Mapping[Any, tuple[int, int]] - | None = None, - constant_values: float - | tuple[float, float] - | Mapping[Any, tuple[float, float]] - | None = None, + stat_length: ( + int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None + ) = None, + constant_values: ( + float | tuple[float, float] | Mapping[Any, tuple[float, float]] | None + ) = None, end_values: int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None = None, reflect_type: PadReflectOptions = None, keep_attrs: bool | None = None, diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 7fc689eef7b..2e689db6980 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -1520,13 +1520,11 @@ def loc(self) -> _LocIndexer[Self]: return _LocIndexer(self) @overload - def __getitem__(self, key: Hashable) -> DataArray: - ... + def __getitem__(self, key: Hashable) -> DataArray: ... # Mapping is Iterable @overload - def __getitem__(self, key: Iterable[Hashable]) -> Self: - ... + def __getitem__(self, key: Iterable[Hashable]) -> Self: ... def __getitem__( self, key: Mapping[Any, Any] | Hashable | Iterable[Hashable] @@ -2151,8 +2149,7 @@ def to_netcdf( unlimited_dims: Iterable[Hashable] | None = None, compute: bool = True, invalid_netcdf: bool = False, - ) -> bytes: - ... + ) -> bytes: ... # compute=False returns dask.Delayed @overload @@ -2168,8 +2165,7 @@ def to_netcdf( *, compute: Literal[False], invalid_netcdf: bool = False, - ) -> Delayed: - ... + ) -> Delayed: ... # default return None @overload @@ -2184,8 +2180,7 @@ def to_netcdf( unlimited_dims: Iterable[Hashable] | None = None, compute: Literal[True] = True, invalid_netcdf: bool = False, - ) -> None: - ... + ) -> None: ... # if compute cannot be evaluated at type check time # we may get back either Delayed or None @@ -2201,8 +2196,7 @@ def to_netcdf( unlimited_dims: Iterable[Hashable] | None = None, compute: bool = True, invalid_netcdf: bool = False, - ) -> Delayed | None: - ... + ) -> Delayed | None: ... def to_netcdf( self, @@ -2333,8 +2327,7 @@ def to_zarr( zarr_version: int | None = None, write_empty_chunks: bool | None = None, chunkmanager_store_kwargs: dict[str, Any] | None = None, - ) -> ZarrStore: - ... + ) -> ZarrStore: ... # compute=False returns dask.Delayed @overload @@ -2356,8 +2349,7 @@ def to_zarr( zarr_version: int | None = None, write_empty_chunks: bool | None = None, chunkmanager_store_kwargs: dict[str, Any] | None = None, - ) -> Delayed: - ... + ) -> Delayed: ... def to_zarr( self, @@ -7921,10 +7913,12 @@ def roll( def sortby( self, - variables: Hashable - | DataArray - | Sequence[Hashable | DataArray] - | Callable[[Self], Hashable | DataArray | list[Hashable | DataArray]], + variables: ( + Hashable + | DataArray + | Sequence[Hashable | DataArray] + | Callable[[Self], Hashable | DataArray | list[Hashable | DataArray]] + ), ascending: bool = True, ) -> Self: """ @@ -8969,10 +8963,9 @@ def pad( self, pad_width: Mapping[Any, int | tuple[int, int]] | None = None, mode: PadModeOptions = "constant", - stat_length: int - | tuple[int, int] - | Mapping[Any, tuple[int, int]] - | None = None, + stat_length: ( + int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None + ) = None, constant_values: ( float | tuple[float, float] | Mapping[Any, tuple[float, float]] | None ) = None, diff --git a/xarray/core/duck_array_ops.py b/xarray/core/duck_array_ops.py index b30ba4c3a78..a740c54380b 100644 --- a/xarray/core/duck_array_ops.py +++ b/xarray/core/duck_array_ops.py @@ -3,6 +3,7 @@ Currently, this means Dask or NumPy arrays. None of these functions should accept or return xarray objects. """ + from __future__ import annotations import contextlib diff --git a/xarray/core/formatting.py b/xarray/core/formatting.py index 92bfe2fbfc4..edc961a6ab5 100644 --- a/xarray/core/formatting.py +++ b/xarray/core/formatting.py @@ -1,5 +1,6 @@ """String formatting routines for __repr__. """ + from __future__ import annotations import contextlib diff --git a/xarray/core/groupby.py b/xarray/core/groupby.py index 93f648277ca..15b3c5086a4 100644 --- a/xarray/core/groupby.py +++ b/xarray/core/groupby.py @@ -272,9 +272,12 @@ def to_array(self) -> DataArray: T_Group = Union["T_DataArray", "IndexVariable", _DummyGroup] -def _ensure_1d( - group: T_Group, obj: T_Xarray -) -> tuple[T_Group, T_Xarray, Hashable | None, list[Hashable],]: +def _ensure_1d(group: T_Group, obj: T_Xarray) -> tuple[ + T_Group, + T_Xarray, + Hashable | None, + list[Hashable], +]: # 1D cases: do nothing if isinstance(group, (IndexVariable, _DummyGroup)) or group.ndim == 1: return group, obj, None, [] diff --git a/xarray/core/indexing.py b/xarray/core/indexing.py index 6e6ce01a41f..cf8c2a3d259 100644 --- a/xarray/core/indexing.py +++ b/xarray/core/indexing.py @@ -1060,9 +1060,11 @@ def _decompose_outer_indexer( # some backends such as h5py supports only 1 vector in indexers # We choose the most efficient axis gains = [ - (np.max(k) - np.min(k) + 1.0) / len(np.unique(k)) - if isinstance(k, np.ndarray) - else 0 + ( + (np.max(k) - np.min(k) + 1.0) / len(np.unique(k)) + if isinstance(k, np.ndarray) + else 0 + ) for k in indexer_elems ] array_index = np.argmax(np.array(gains)) if len(gains) > 0 else None @@ -1275,9 +1277,11 @@ def posify_mask_indexer(indexer): replaced by an adjacent non-masked element. """ key = tuple( - _posify_mask_subindexer(k.ravel()).reshape(k.shape) - if isinstance(k, np.ndarray) - else k + ( + _posify_mask_subindexer(k.ravel()).reshape(k.shape) + if isinstance(k, np.ndarray) + else k + ) for k in indexer.tuple ) return type(indexer)(key) diff --git a/xarray/core/missing.py b/xarray/core/missing.py index c6592f739da..186ec121ca9 100644 --- a/xarray/core/missing.py +++ b/xarray/core/missing.py @@ -469,9 +469,9 @@ def _get_interpolator( returns interpolator class and keyword arguments for the class """ - interp_class: type[NumpyInterpolator] | type[ScipyInterpolator] | type[ - SplineInterpolator - ] + interp_class: ( + type[NumpyInterpolator] | type[ScipyInterpolator] | type[SplineInterpolator] + ) interp1d_methods = get_args(Interp1dOptions) valid_methods = tuple(vv for v in get_args(InterpOptions) for vv in get_args(v)) diff --git a/xarray/core/ops.py b/xarray/core/ops.py index b23d586fb79..c67b46692b8 100644 --- a/xarray/core/ops.py +++ b/xarray/core/ops.py @@ -4,6 +4,7 @@ NumPy's __array_ufunc__ and mixin classes instead of the unintuitive "inject" functions. """ + from __future__ import annotations import operator diff --git a/xarray/core/parallel.py b/xarray/core/parallel.py index 3b47520a78c..3d9c81f5da7 100644 --- a/xarray/core/parallel.py +++ b/xarray/core/parallel.py @@ -537,9 +537,13 @@ def _wrapper( chunk_index = dict(zip(ichunk.keys(), chunk_tuple)) blocked_args = [ - subset_dataset_to_block(graph, gname, arg, input_chunk_bounds, chunk_index) - if isxr - else arg + ( + subset_dataset_to_block( + graph, gname, arg, input_chunk_bounds, chunk_index + ) + if isxr + else arg + ) for isxr, arg in zip(is_xarray, npargs) ] diff --git a/xarray/core/parallelcompat.py b/xarray/core/parallelcompat.py index 23f3c6a80ec..c009ef48419 100644 --- a/xarray/core/parallelcompat.py +++ b/xarray/core/parallelcompat.py @@ -3,6 +3,7 @@ It could later be used as the basis for a public interface allowing any N frameworks to interoperate with xarray, but for now it is just a private experiment. """ + from __future__ import annotations import functools diff --git a/xarray/core/resample_cftime.py b/xarray/core/resample_cftime.py index 7241faa1c61..216bd8fca6b 100644 --- a/xarray/core/resample_cftime.py +++ b/xarray/core/resample_cftime.py @@ -1,4 +1,5 @@ """Resampling for CFTimeIndex. Does not support non-integer freq.""" + # The mechanisms for resampling CFTimeIndex was copied and adapted from # the source code defined in pandas.core.resample # diff --git a/xarray/core/types.py b/xarray/core/types.py index 8c3164c52fa..410cf3de00b 100644 --- a/xarray/core/types.py +++ b/xarray/core/types.py @@ -102,16 +102,13 @@ class Alignable(Protocol): """ @property - def dims(self) -> Frozen[Hashable, int] | tuple[Hashable, ...]: - ... + def dims(self) -> Frozen[Hashable, int] | tuple[Hashable, ...]: ... @property - def sizes(self) -> Mapping[Hashable, int]: - ... + def sizes(self) -> Mapping[Hashable, int]: ... @property - def xindexes(self) -> Indexes[Index]: - ... + def xindexes(self) -> Indexes[Index]: ... def _reindex_callback( self, @@ -122,27 +119,22 @@ def _reindex_callback( fill_value: Any, exclude_dims: frozenset[Hashable], exclude_vars: frozenset[Hashable], - ) -> Self: - ... + ) -> Self: ... def _overwrite_indexes( self, indexes: Mapping[Any, Index], variables: Mapping[Any, Variable] | None = None, - ) -> Self: - ... + ) -> Self: ... - def __len__(self) -> int: - ... + def __len__(self) -> int: ... - def __iter__(self) -> Iterator[Hashable]: - ... + def __iter__(self) -> Iterator[Hashable]: ... def copy( self, deep: bool = False, - ) -> Self: - ... + ) -> Self: ... T_Alignable = TypeVar("T_Alignable", bound="Alignable") diff --git a/xarray/core/utils.py b/xarray/core/utils.py index b514e455230..587e0a39be2 100644 --- a/xarray/core/utils.py +++ b/xarray/core/utils.py @@ -1,4 +1,5 @@ """Internal utilities; not for external use""" + # Some functions in this module are derived from functions in pandas. For # reference, here is a copy of the pandas copyright notice: @@ -504,12 +505,10 @@ def __getitem__(self, key: K) -> V: return super().__getitem__(key) @overload - def get(self, key: K, /) -> V | None: - ... + def get(self, key: K, /) -> V | None: ... @overload - def get(self, key: K, /, default: V | T) -> V | T: - ... + def get(self, key: K, /, default: V | T) -> V | T: ... def get(self, key: K, default: T | None = None) -> V | T | None: self._warn() @@ -961,8 +960,7 @@ def parse_dims( *, check_exists: bool = True, replace_none: Literal[True] = True, -) -> tuple[Hashable, ...]: - ... +) -> tuple[Hashable, ...]: ... @overload @@ -972,8 +970,7 @@ def parse_dims( *, check_exists: bool = True, replace_none: Literal[False], -) -> tuple[Hashable, ...] | None | ellipsis: - ... +) -> tuple[Hashable, ...] | None | ellipsis: ... def parse_dims( @@ -1024,8 +1021,7 @@ def parse_ordered_dims( *, check_exists: bool = True, replace_none: Literal[True] = True, -) -> tuple[Hashable, ...]: - ... +) -> tuple[Hashable, ...]: ... @overload @@ -1035,8 +1031,7 @@ def parse_ordered_dims( *, check_exists: bool = True, replace_none: Literal[False], -) -> tuple[Hashable, ...] | None | ellipsis: - ... +) -> tuple[Hashable, ...] | None | ellipsis: ... def parse_ordered_dims( @@ -1118,12 +1113,10 @@ def __init__(self, accessor: type[_Accessor]) -> None: self._accessor = accessor @overload - def __get__(self, obj: None, cls) -> type[_Accessor]: - ... + def __get__(self, obj: None, cls) -> type[_Accessor]: ... @overload - def __get__(self, obj: object, cls) -> _Accessor: - ... + def __get__(self, obj: object, cls) -> _Accessor: ... def __get__(self, obj: None | object, cls) -> type[_Accessor] | _Accessor: if obj is None: diff --git a/xarray/core/variable.py b/xarray/core/variable.py index 32323bb2e64..a39981bb8fc 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -1231,14 +1231,12 @@ def pad( self, pad_width: Mapping[Any, int | tuple[int, int]] | None = None, mode: PadModeOptions = "constant", - stat_length: int - | tuple[int, int] - | Mapping[Any, tuple[int, int]] - | None = None, - constant_values: float - | tuple[float, float] - | Mapping[Any, tuple[float, float]] - | None = None, + stat_length: ( + int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None + ) = None, + constant_values: ( + float | tuple[float, float] | Mapping[Any, tuple[float, float]] | None + ) = None, end_values: int | tuple[int, int] | Mapping[Any, tuple[int, int]] | None = None, reflect_type: PadReflectOptions = None, keep_attrs: bool | None = None, diff --git a/xarray/indexes/__init__.py b/xarray/indexes/__init__.py index 143d7a58fda..b1bf7a1af11 100644 --- a/xarray/indexes/__init__.py +++ b/xarray/indexes/__init__.py @@ -2,6 +2,7 @@ DataArray objects. """ + from xarray.core.indexes import Index, PandasIndex, PandasMultiIndex __all__ = ["Index", "PandasIndex", "PandasMultiIndex"] diff --git a/xarray/namedarray/_aggregations.py b/xarray/namedarray/_aggregations.py index 76dfb18d068..18b825d334a 100644 --- a/xarray/namedarray/_aggregations.py +++ b/xarray/namedarray/_aggregations.py @@ -1,4 +1,5 @@ """Mixin classes with reduction operations.""" + # This file was generated using xarray.util.generate_aggregations. Do not edit manually. from __future__ import annotations diff --git a/xarray/namedarray/_typing.py b/xarray/namedarray/_typing.py index 835f60e682d..2a07389a349 100644 --- a/xarray/namedarray/_typing.py +++ b/xarray/namedarray/_typing.py @@ -43,8 +43,7 @@ class Default(Enum): @runtime_checkable class _SupportsDType(Protocol[_DType_co]): @property - def dtype(self) -> _DType_co: - ... + def dtype(self) -> _DType_co: ... _DTypeLike = Union[ @@ -84,14 +83,12 @@ def dtype(self) -> _DType_co: class _SupportsReal(Protocol[_T_co]): @property - def real(self) -> _T_co: - ... + def real(self) -> _T_co: ... class _SupportsImag(Protocol[_T_co]): @property - def imag(self) -> _T_co: - ... + def imag(self) -> _T_co: ... @runtime_checkable @@ -103,12 +100,10 @@ class _array(Protocol[_ShapeType_co, _DType_co]): """ @property - def shape(self) -> _Shape: - ... + def shape(self) -> _Shape: ... @property - def dtype(self) -> _DType_co: - ... + def dtype(self) -> _DType_co: ... @runtime_checkable @@ -124,34 +119,30 @@ class _arrayfunction( @overload def __getitem__( self, key: _arrayfunction[Any, Any] | tuple[_arrayfunction[Any, Any], ...], / - ) -> _arrayfunction[Any, _DType_co]: - ... + ) -> _arrayfunction[Any, _DType_co]: ... @overload - def __getitem__(self, key: _IndexKeyLike, /) -> Any: - ... + def __getitem__(self, key: _IndexKeyLike, /) -> Any: ... def __getitem__( self, - key: _IndexKeyLike - | _arrayfunction[Any, Any] - | tuple[_arrayfunction[Any, Any], ...], + key: ( + _IndexKeyLike + | _arrayfunction[Any, Any] + | tuple[_arrayfunction[Any, Any], ...] + ), /, - ) -> _arrayfunction[Any, _DType_co] | Any: - ... + ) -> _arrayfunction[Any, _DType_co] | Any: ... @overload - def __array__(self, dtype: None = ..., /) -> np.ndarray[Any, _DType_co]: - ... + def __array__(self, dtype: None = ..., /) -> np.ndarray[Any, _DType_co]: ... @overload - def __array__(self, dtype: _DType, /) -> np.ndarray[Any, _DType]: - ... + def __array__(self, dtype: _DType, /) -> np.ndarray[Any, _DType]: ... def __array__( self, dtype: _DType | None = ..., / - ) -> np.ndarray[Any, _DType] | np.ndarray[Any, _DType_co]: - ... + ) -> np.ndarray[Any, _DType] | np.ndarray[Any, _DType_co]: ... # TODO: Should return the same subclass but with a new dtype generic. # https://github.com/python/typing/issues/548 @@ -161,8 +152,7 @@ def __array_ufunc__( method: Any, *inputs: Any, **kwargs: Any, - ) -> Any: - ... + ) -> Any: ... # TODO: Should return the same subclass but with a new dtype generic. # https://github.com/python/typing/issues/548 @@ -172,16 +162,13 @@ def __array_function__( types: Iterable[type], args: Iterable[Any], kwargs: Mapping[str, Any], - ) -> Any: - ... + ) -> Any: ... @property - def imag(self) -> _arrayfunction[_ShapeType_co, Any]: - ... + def imag(self) -> _arrayfunction[_ShapeType_co, Any]: ... @property - def real(self) -> _arrayfunction[_ShapeType_co, Any]: - ... + def real(self) -> _arrayfunction[_ShapeType_co, Any]: ... @runtime_checkable @@ -194,14 +181,13 @@ class _arrayapi(_array[_ShapeType_co, _DType_co], Protocol[_ShapeType_co, _DType def __getitem__( self, - key: _IndexKeyLike - | Any, # TODO: Any should be _arrayapi[Any, _dtype[np.integer]] + key: ( + _IndexKeyLike | Any + ), # TODO: Any should be _arrayapi[Any, _dtype[np.integer]] /, - ) -> _arrayapi[Any, Any]: - ... + ) -> _arrayapi[Any, Any]: ... - def __array_namespace__(self) -> ModuleType: - ... + def __array_namespace__(self) -> ModuleType: ... # NamedArray can most likely use both __array_function__ and __array_namespace__: @@ -226,8 +212,7 @@ class _chunkedarray( """ @property - def chunks(self) -> _Chunks: - ... + def chunks(self) -> _Chunks: ... @runtime_checkable @@ -241,8 +226,7 @@ class _chunkedarrayfunction( """ @property - def chunks(self) -> _Chunks: - ... + def chunks(self) -> _Chunks: ... @runtime_checkable @@ -256,8 +240,7 @@ class _chunkedarrayapi( """ @property - def chunks(self) -> _Chunks: - ... + def chunks(self) -> _Chunks: ... # NamedArray can most likely use both __array_function__ and __array_namespace__: @@ -278,8 +261,7 @@ class _sparsearray( Corresponds to np.ndarray. """ - def todense(self) -> np.ndarray[Any, _DType_co]: - ... + def todense(self) -> np.ndarray[Any, _DType_co]: ... @runtime_checkable @@ -292,8 +274,7 @@ class _sparsearrayfunction( Corresponds to np.ndarray. """ - def todense(self) -> np.ndarray[Any, _DType_co]: - ... + def todense(self) -> np.ndarray[Any, _DType_co]: ... @runtime_checkable @@ -306,8 +287,7 @@ class _sparsearrayapi( Corresponds to np.ndarray. """ - def todense(self) -> np.ndarray[Any, _DType_co]: - ... + def todense(self) -> np.ndarray[Any, _DType_co]: ... # NamedArray can most likely use both __array_function__ and __array_namespace__: diff --git a/xarray/namedarray/core.py b/xarray/namedarray/core.py index f202a18c04a..e2830002e11 100644 --- a/xarray/namedarray/core.py +++ b/xarray/namedarray/core.py @@ -93,8 +93,7 @@ def _new( dims: _DimsLike | Default = ..., data: duckarray[_ShapeType, _DType] = ..., attrs: _AttrsLike | Default = ..., -) -> NamedArray[_ShapeType, _DType]: - ... +) -> NamedArray[_ShapeType, _DType]: ... @overload @@ -103,8 +102,7 @@ def _new( dims: _DimsLike | Default = ..., data: Default = ..., attrs: _AttrsLike | Default = ..., -) -> NamedArray[_ShapeType_co, _DType_co]: - ... +) -> NamedArray[_ShapeType_co, _DType_co]: ... def _new( @@ -152,8 +150,7 @@ def from_array( dims: _DimsLike, data: duckarray[_ShapeType, _DType], attrs: _AttrsLike = ..., -) -> NamedArray[_ShapeType, _DType]: - ... +) -> NamedArray[_ShapeType, _DType]: ... @overload @@ -161,8 +158,7 @@ def from_array( dims: _DimsLike, data: ArrayLike, attrs: _AttrsLike = ..., -) -> NamedArray[Any, Any]: - ... +) -> NamedArray[Any, Any]: ... def from_array( @@ -274,8 +270,7 @@ def _new( dims: _DimsLike | Default = ..., data: duckarray[_ShapeType, _DType] = ..., attrs: _AttrsLike | Default = ..., - ) -> NamedArray[_ShapeType, _DType]: - ... + ) -> NamedArray[_ShapeType, _DType]: ... @overload def _new( @@ -283,8 +278,7 @@ def _new( dims: _DimsLike | Default = ..., data: Default = ..., attrs: _AttrsLike | Default = ..., - ) -> NamedArray[_ShapeType_co, _DType_co]: - ... + ) -> NamedArray[_ShapeType_co, _DType_co]: ... def _new( self, @@ -649,12 +643,10 @@ def _dask_finalize( return type(self)(self._dims, data, attrs=self._attrs) @overload - def get_axis_num(self, dim: Iterable[Hashable]) -> tuple[int, ...]: - ... + def get_axis_num(self, dim: Iterable[Hashable]) -> tuple[int, ...]: ... @overload - def get_axis_num(self, dim: Hashable) -> int: - ... + def get_axis_num(self, dim: Hashable) -> int: ... def get_axis_num(self, dim: Hashable | Iterable[Hashable]) -> int | tuple[int, ...]: """Return axis number(s) corresponding to dimension(s) in this array. diff --git a/xarray/plot/__init__.py b/xarray/plot/__init__.py index 28aac6edd9e..ae7a0012b32 100644 --- a/xarray/plot/__init__.py +++ b/xarray/plot/__init__.py @@ -6,6 +6,7 @@ DataArray.plot._____ Dataset.plot._____ """ + from xarray.plot.dataarray_plot import ( contour, contourf, diff --git a/xarray/plot/accessor.py b/xarray/plot/accessor.py index 203bae2691f..9db4ae4e3f7 100644 --- a/xarray/plot/accessor.py +++ b/xarray/plot/accessor.py @@ -77,8 +77,7 @@ def line( # type: ignore[misc,unused-ignore] # None is hashable :( add_legend: bool = True, _labels: bool = True, **kwargs: Any, - ) -> list[Line3D]: - ... + ) -> list[Line3D]: ... @overload def line( @@ -104,8 +103,7 @@ def line( add_legend: bool = True, _labels: bool = True, **kwargs: Any, - ) -> FacetGrid[DataArray]: - ... + ) -> FacetGrid[DataArray]: ... @overload def line( @@ -131,8 +129,7 @@ def line( add_legend: bool = True, _labels: bool = True, **kwargs: Any, - ) -> FacetGrid[DataArray]: - ... + ) -> FacetGrid[DataArray]: ... @functools.wraps(dataarray_plot.line, assigned=("__doc__",)) def line(self, *args, **kwargs) -> list[Line3D] | FacetGrid[DataArray]: @@ -148,8 +145,7 @@ def step( # type: ignore[misc,unused-ignore] # None is hashable :( row: None = None, # no wrap -> primitive col: None = None, # no wrap -> primitive **kwargs: Any, - ) -> list[Line3D]: - ... + ) -> list[Line3D]: ... @overload def step( @@ -161,8 +157,7 @@ def step( row: Hashable, # wrap -> FacetGrid col: Hashable | None = None, **kwargs: Any, - ) -> FacetGrid[DataArray]: - ... + ) -> FacetGrid[DataArray]: ... @overload def step( @@ -174,8 +169,7 @@ def step( row: Hashable | None = None, col: Hashable, # wrap -> FacetGrid **kwargs: Any, - ) -> FacetGrid[DataArray]: - ... + ) -> FacetGrid[DataArray]: ... @functools.wraps(dataarray_plot.step, assigned=("__doc__",)) def step(self, *args, **kwargs) -> list[Line3D] | FacetGrid[DataArray]: @@ -219,8 +213,7 @@ def scatter( # type: ignore[misc,unused-ignore] # None is hashable :( extend=None, levels=None, **kwargs, - ) -> PathCollection: - ... + ) -> PathCollection: ... @overload def scatter( @@ -260,8 +253,7 @@ def scatter( extend=None, levels=None, **kwargs, - ) -> FacetGrid[DataArray]: - ... + ) -> FacetGrid[DataArray]: ... @overload def scatter( @@ -301,8 +293,7 @@ def scatter( extend=None, levels=None, **kwargs, - ) -> FacetGrid[DataArray]: - ... + ) -> FacetGrid[DataArray]: ... @functools.wraps(dataarray_plot.scatter, assigned=("__doc__",)) def scatter(self, *args, **kwargs) -> PathCollection | FacetGrid[DataArray]: @@ -345,8 +336,7 @@ def imshow( # type: ignore[misc,unused-ignore] # None is hashable :( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> AxesImage: - ... + ) -> AxesImage: ... @overload def imshow( @@ -385,8 +375,7 @@ def imshow( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> FacetGrid[DataArray]: - ... + ) -> FacetGrid[DataArray]: ... @overload def imshow( @@ -425,8 +414,7 @@ def imshow( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> FacetGrid[DataArray]: - ... + ) -> FacetGrid[DataArray]: ... @functools.wraps(dataarray_plot.imshow, assigned=("__doc__",)) def imshow(self, *args, **kwargs) -> AxesImage | FacetGrid[DataArray]: @@ -469,8 +457,7 @@ def contour( # type: ignore[misc,unused-ignore] # None is hashable :( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> QuadContourSet: - ... + ) -> QuadContourSet: ... @overload def contour( @@ -509,8 +496,7 @@ def contour( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> FacetGrid[DataArray]: - ... + ) -> FacetGrid[DataArray]: ... @overload def contour( @@ -549,8 +535,7 @@ def contour( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> FacetGrid[DataArray]: - ... + ) -> FacetGrid[DataArray]: ... @functools.wraps(dataarray_plot.contour, assigned=("__doc__",)) def contour(self, *args, **kwargs) -> QuadContourSet | FacetGrid[DataArray]: @@ -593,8 +578,7 @@ def contourf( # type: ignore[misc,unused-ignore] # None is hashable :( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> QuadContourSet: - ... + ) -> QuadContourSet: ... @overload def contourf( @@ -633,8 +617,7 @@ def contourf( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> FacetGrid[DataArray]: - ... + ) -> FacetGrid[DataArray]: ... @overload def contourf( @@ -673,8 +656,7 @@ def contourf( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> FacetGrid: - ... + ) -> FacetGrid: ... @functools.wraps(dataarray_plot.contourf, assigned=("__doc__",)) def contourf(self, *args, **kwargs) -> QuadContourSet | FacetGrid[DataArray]: @@ -717,8 +699,7 @@ def pcolormesh( # type: ignore[misc,unused-ignore] # None is hashable :( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> QuadMesh: - ... + ) -> QuadMesh: ... @overload def pcolormesh( @@ -757,8 +738,7 @@ def pcolormesh( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> FacetGrid[DataArray]: - ... + ) -> FacetGrid[DataArray]: ... @overload def pcolormesh( @@ -797,8 +777,7 @@ def pcolormesh( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> FacetGrid[DataArray]: - ... + ) -> FacetGrid[DataArray]: ... @functools.wraps(dataarray_plot.pcolormesh, assigned=("__doc__",)) def pcolormesh(self, *args, **kwargs) -> QuadMesh | FacetGrid[DataArray]: @@ -841,8 +820,7 @@ def surface( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> Poly3DCollection: - ... + ) -> Poly3DCollection: ... @overload def surface( @@ -881,8 +859,7 @@ def surface( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> FacetGrid: - ... + ) -> FacetGrid: ... @overload def surface( @@ -921,8 +898,7 @@ def surface( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> FacetGrid: - ... + ) -> FacetGrid: ... @functools.wraps(dataarray_plot.surface, assigned=("__doc__",)) def surface(self, *args, **kwargs) -> Poly3DCollection: @@ -985,8 +961,7 @@ def scatter( # type: ignore[misc,unused-ignore] # None is hashable :( extend=None, levels=None, **kwargs: Any, - ) -> PathCollection: - ... + ) -> PathCollection: ... @overload def scatter( @@ -1026,8 +1001,7 @@ def scatter( extend=None, levels=None, **kwargs: Any, - ) -> FacetGrid[Dataset]: - ... + ) -> FacetGrid[Dataset]: ... @overload def scatter( @@ -1067,8 +1041,7 @@ def scatter( extend=None, levels=None, **kwargs: Any, - ) -> FacetGrid[Dataset]: - ... + ) -> FacetGrid[Dataset]: ... @functools.wraps(dataset_plot.scatter, assigned=("__doc__",)) def scatter(self, *args, **kwargs) -> PathCollection | FacetGrid[Dataset]: @@ -1108,8 +1081,7 @@ def quiver( # type: ignore[misc,unused-ignore] # None is hashable :( extend=None, cmap=None, **kwargs: Any, - ) -> Quiver: - ... + ) -> Quiver: ... @overload def quiver( @@ -1145,8 +1117,7 @@ def quiver( extend=None, cmap=None, **kwargs: Any, - ) -> FacetGrid[Dataset]: - ... + ) -> FacetGrid[Dataset]: ... @overload def quiver( @@ -1182,8 +1153,7 @@ def quiver( extend=None, cmap=None, **kwargs: Any, - ) -> FacetGrid[Dataset]: - ... + ) -> FacetGrid[Dataset]: ... @functools.wraps(dataset_plot.quiver, assigned=("__doc__",)) def quiver(self, *args, **kwargs) -> Quiver | FacetGrid[Dataset]: @@ -1223,8 +1193,7 @@ def streamplot( # type: ignore[misc,unused-ignore] # None is hashable :( extend=None, cmap=None, **kwargs: Any, - ) -> LineCollection: - ... + ) -> LineCollection: ... @overload def streamplot( @@ -1260,8 +1229,7 @@ def streamplot( extend=None, cmap=None, **kwargs: Any, - ) -> FacetGrid[Dataset]: - ... + ) -> FacetGrid[Dataset]: ... @overload def streamplot( @@ -1297,8 +1265,7 @@ def streamplot( extend=None, cmap=None, **kwargs: Any, - ) -> FacetGrid[Dataset]: - ... + ) -> FacetGrid[Dataset]: ... @functools.wraps(dataset_plot.streamplot, assigned=("__doc__",)) def streamplot(self, *args, **kwargs) -> LineCollection | FacetGrid[Dataset]: diff --git a/xarray/plot/dataarray_plot.py b/xarray/plot/dataarray_plot.py index aebc3c2bac1..8386161bf29 100644 --- a/xarray/plot/dataarray_plot.py +++ b/xarray/plot/dataarray_plot.py @@ -333,8 +333,7 @@ def line( # type: ignore[misc,unused-ignore] # None is hashable :( add_legend: bool = True, _labels: bool = True, **kwargs: Any, -) -> list[Line3D]: - ... +) -> list[Line3D]: ... @overload @@ -361,8 +360,7 @@ def line( add_legend: bool = True, _labels: bool = True, **kwargs: Any, -) -> FacetGrid[T_DataArray]: - ... +) -> FacetGrid[T_DataArray]: ... @overload @@ -389,8 +387,7 @@ def line( add_legend: bool = True, _labels: bool = True, **kwargs: Any, -) -> FacetGrid[T_DataArray]: - ... +) -> FacetGrid[T_DataArray]: ... # This function signature should not change so that it can use @@ -544,8 +541,7 @@ def step( # type: ignore[misc,unused-ignore] # None is hashable :( row: None = None, # no wrap -> primitive col: None = None, # no wrap -> primitive **kwargs: Any, -) -> list[Line3D]: - ... +) -> list[Line3D]: ... @overload @@ -558,8 +554,7 @@ def step( row: Hashable, # wrap -> FacetGrid col: Hashable | None = None, **kwargs: Any, -) -> FacetGrid[DataArray]: - ... +) -> FacetGrid[DataArray]: ... @overload @@ -572,8 +567,7 @@ def step( row: Hashable | None = None, col: Hashable, # wrap -> FacetGrid **kwargs: Any, -) -> FacetGrid[DataArray]: - ... +) -> FacetGrid[DataArray]: ... def step( @@ -1042,9 +1036,11 @@ def newplotfunc( if add_legend_: if plotfunc.__name__ in ["scatter", "line"]: _add_legend( - hueplt_norm - if add_legend or not add_colorbar_ - else _Normalize(None), + ( + hueplt_norm + if add_legend or not add_colorbar_ + else _Normalize(None) + ), sizeplt_norm, primitive, legend_ax=ax, @@ -1144,8 +1140,7 @@ def scatter( # type: ignore[misc,unused-ignore] # None is hashable :( extend: ExtendOptions = None, levels: ArrayLike | None = None, **kwargs, -) -> PathCollection: - ... +) -> PathCollection: ... @overload @@ -1186,8 +1181,7 @@ def scatter( extend: ExtendOptions = None, levels: ArrayLike | None = None, **kwargs, -) -> FacetGrid[T_DataArray]: - ... +) -> FacetGrid[T_DataArray]: ... @overload @@ -1228,8 +1222,7 @@ def scatter( extend: ExtendOptions = None, levels: ArrayLike | None = None, **kwargs, -) -> FacetGrid[T_DataArray]: - ... +) -> FacetGrid[T_DataArray]: ... @_plot1d @@ -1696,8 +1689,7 @@ def imshow( # type: ignore[misc,unused-ignore] # None is hashable :( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> AxesImage: - ... +) -> AxesImage: ... @overload @@ -1737,8 +1729,7 @@ def imshow( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: - ... +) -> FacetGrid[T_DataArray]: ... @overload @@ -1778,8 +1769,7 @@ def imshow( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: - ... +) -> FacetGrid[T_DataArray]: ... @_plot2d @@ -1915,8 +1905,7 @@ def contour( # type: ignore[misc,unused-ignore] # None is hashable :( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> QuadContourSet: - ... +) -> QuadContourSet: ... @overload @@ -1956,8 +1945,7 @@ def contour( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: - ... +) -> FacetGrid[T_DataArray]: ... @overload @@ -1997,8 +1985,7 @@ def contour( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: - ... +) -> FacetGrid[T_DataArray]: ... @_plot2d @@ -2051,8 +2038,7 @@ def contourf( # type: ignore[misc,unused-ignore] # None is hashable :( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> QuadContourSet: - ... +) -> QuadContourSet: ... @overload @@ -2092,8 +2078,7 @@ def contourf( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: - ... +) -> FacetGrid[T_DataArray]: ... @overload @@ -2133,8 +2118,7 @@ def contourf( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: - ... +) -> FacetGrid[T_DataArray]: ... @_plot2d @@ -2187,8 +2171,7 @@ def pcolormesh( # type: ignore[misc,unused-ignore] # None is hashable :( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> QuadMesh: - ... +) -> QuadMesh: ... @overload @@ -2228,8 +2211,7 @@ def pcolormesh( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: - ... +) -> FacetGrid[T_DataArray]: ... @overload @@ -2269,8 +2251,7 @@ def pcolormesh( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: - ... +) -> FacetGrid[T_DataArray]: ... @_plot2d @@ -2374,8 +2355,7 @@ def surface( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> Poly3DCollection: - ... +) -> Poly3DCollection: ... @overload @@ -2415,8 +2395,7 @@ def surface( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: - ... +) -> FacetGrid[T_DataArray]: ... @overload @@ -2456,8 +2435,7 @@ def surface( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: - ... +) -> FacetGrid[T_DataArray]: ... @_plot2d diff --git a/xarray/plot/dataset_plot.py b/xarray/plot/dataset_plot.py index a3ca201eec4..edc2bf43629 100644 --- a/xarray/plot/dataset_plot.py +++ b/xarray/plot/dataset_plot.py @@ -354,8 +354,7 @@ def quiver( # type: ignore[misc,unused-ignore] # None is hashable :( extend: ExtendOptions = None, cmap: str | Colormap | None = None, **kwargs: Any, -) -> Quiver: - ... +) -> Quiver: ... @overload @@ -392,8 +391,7 @@ def quiver( extend: ExtendOptions = None, cmap: str | Colormap | None = None, **kwargs: Any, -) -> FacetGrid[Dataset]: - ... +) -> FacetGrid[Dataset]: ... @overload @@ -430,8 +428,7 @@ def quiver( extend: ExtendOptions = None, cmap: str | Colormap | None = None, **kwargs: Any, -) -> FacetGrid[Dataset]: - ... +) -> FacetGrid[Dataset]: ... @_dsplot @@ -508,8 +505,7 @@ def streamplot( # type: ignore[misc,unused-ignore] # None is hashable :( extend: ExtendOptions = None, cmap: str | Colormap | None = None, **kwargs: Any, -) -> LineCollection: - ... +) -> LineCollection: ... @overload @@ -546,8 +542,7 @@ def streamplot( extend: ExtendOptions = None, cmap: str | Colormap | None = None, **kwargs: Any, -) -> FacetGrid[Dataset]: - ... +) -> FacetGrid[Dataset]: ... @overload @@ -584,8 +579,7 @@ def streamplot( extend: ExtendOptions = None, cmap: str | Colormap | None = None, **kwargs: Any, -) -> FacetGrid[Dataset]: - ... +) -> FacetGrid[Dataset]: ... @_dsplot @@ -786,8 +780,7 @@ def scatter( # type: ignore[misc,unused-ignore] # None is hashable :( extend: ExtendOptions = None, levels: ArrayLike | None = None, **kwargs: Any, -) -> PathCollection: - ... +) -> PathCollection: ... @overload @@ -828,8 +821,7 @@ def scatter( extend: ExtendOptions = None, levels: ArrayLike | None = None, **kwargs: Any, -) -> FacetGrid[DataArray]: - ... +) -> FacetGrid[DataArray]: ... @overload @@ -870,8 +862,7 @@ def scatter( extend: ExtendOptions = None, levels: ArrayLike | None = None, **kwargs: Any, -) -> FacetGrid[DataArray]: - ... +) -> FacetGrid[DataArray]: ... @_update_doc_to_dataset(dataarray_plot.scatter) diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index 903780b1137..f9355dda113 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -1291,16 +1291,14 @@ def _infer_meta_data(ds, x, y, hue, hue_style, add_guide, funcname): def _parse_size( data: None, norm: tuple[float | None, float | None, bool] | Normalize | None, -) -> None: - ... +) -> None: ... @overload def _parse_size( data: DataArray, norm: tuple[float | None, float | None, bool] | Normalize | None, -) -> pd.Series: - ... +) -> pd.Series: ... # copied from seaborn @@ -1445,12 +1443,10 @@ def data_is_numeric(self) -> bool: return self._data_is_numeric @overload - def _calc_widths(self, y: np.ndarray) -> np.ndarray: - ... + def _calc_widths(self, y: np.ndarray) -> np.ndarray: ... @overload - def _calc_widths(self, y: DataArray) -> DataArray: - ... + def _calc_widths(self, y: DataArray) -> DataArray: ... def _calc_widths(self, y: np.ndarray | DataArray) -> np.ndarray | DataArray: """ @@ -1472,12 +1468,10 @@ def _calc_widths(self, y: np.ndarray | DataArray) -> np.ndarray | DataArray: return widths @overload - def _indexes_centered(self, x: np.ndarray) -> np.ndarray: - ... + def _indexes_centered(self, x: np.ndarray) -> np.ndarray: ... @overload - def _indexes_centered(self, x: DataArray) -> DataArray: - ... + def _indexes_centered(self, x: DataArray) -> DataArray: ... def _indexes_centered(self, x: np.ndarray | DataArray) -> np.ndarray | DataArray: """ diff --git a/xarray/testing/assertions.py b/xarray/testing/assertions.py index faa595a64b6..6418eb79b8b 100644 --- a/xarray/testing/assertions.py +++ b/xarray/testing/assertions.py @@ -1,4 +1,5 @@ """Testing functions exposed to the user API""" + import functools import warnings from collections.abc import Hashable diff --git a/xarray/testing/strategies.py b/xarray/testing/strategies.py index d08cbc0b584..c5a7afdf54e 100644 --- a/xarray/testing/strategies.py +++ b/xarray/testing/strategies.py @@ -36,8 +36,7 @@ def __call__( *, shape: "_ShapeLike", dtype: "_DTypeLikeNested", - ) -> st.SearchStrategy[T_DuckArray]: - ... + ) -> st.SearchStrategy[T_DuckArray]: ... def supported_dtypes() -> st.SearchStrategy[np.dtype]: @@ -368,8 +367,7 @@ def unique_subset_of( *, min_size: int = 0, max_size: Union[int, None] = None, -) -> st.SearchStrategy[Sequence[Hashable]]: - ... +) -> st.SearchStrategy[Sequence[Hashable]]: ... @overload @@ -378,8 +376,7 @@ def unique_subset_of( *, min_size: int = 0, max_size: Union[int, None] = None, -) -> st.SearchStrategy[Mapping[Hashable, Any]]: - ... +) -> st.SearchStrategy[Mapping[Hashable, Any]]: ... @st.composite diff --git a/xarray/tests/test_accessor_str.py b/xarray/tests/test_accessor_str.py index dc325a84748..e0c9619b4e7 100644 --- a/xarray/tests/test_accessor_str.py +++ b/xarray/tests/test_accessor_str.py @@ -291,9 +291,7 @@ def test_case_str() -> None: exp_norm_nfc = xr.DataArray(["SOme wOrd DŽ ß ᾛ ΣΣ ffi⁵Å Ç Ⅰ"]).astype(np.str_) exp_norm_nfkc = xr.DataArray(["SOme wOrd DŽ ß ᾛ ΣΣ ffi5Å Ç I"]).astype(np.str_) exp_norm_nfd = xr.DataArray(["SOme wOrd DŽ ß ᾛ ΣΣ ffi⁵Å Ç Ⅰ"]).astype(np.str_) - exp_norm_nfkd = xr.DataArray(["SOme wOrd DŽ ß ᾛ ΣΣ ffi5Å Ç I"]).astype( - np.str_ - ) + exp_norm_nfkd = xr.DataArray(["SOme wOrd DŽ ß ᾛ ΣΣ ffi5Å Ç I"]).astype(np.str_) res_capitalized = value.str.capitalize() res_casefolded = value.str.casefold() diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index 0eaa7ee7361..0863974f449 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -2133,7 +2133,10 @@ def test_non_existent_store(self) -> None: def test_with_chunkstore(self) -> None: expected = create_test_data() - with self.create_zarr_target() as store_target, self.create_zarr_target() as chunk_store: + with ( + self.create_zarr_target() as store_target, + self.create_zarr_target() as chunk_store, + ): save_kwargs = {"chunk_store": chunk_store} self.save(expected, store_target, **save_kwargs) # the chunk store must have been populated with some entries @@ -4569,18 +4572,18 @@ def test_inline_array(self) -> None: def num_graph_nodes(obj): return len(obj.__dask_graph__()) - with open_dataset( - tmp, inline_array=False, chunks=chunks - ) as not_inlined_ds, open_dataset( - tmp, inline_array=True, chunks=chunks - ) as inlined_ds: + with ( + open_dataset(tmp, inline_array=False, chunks=chunks) as not_inlined_ds, + open_dataset(tmp, inline_array=True, chunks=chunks) as inlined_ds, + ): assert num_graph_nodes(inlined_ds) < num_graph_nodes(not_inlined_ds) - with open_dataarray( - tmp, inline_array=False, chunks=chunks - ) as not_inlined_da, open_dataarray( - tmp, inline_array=True, chunks=chunks - ) as inlined_da: + with ( + open_dataarray( + tmp, inline_array=False, chunks=chunks + ) as not_inlined_da, + open_dataarray(tmp, inline_array=True, chunks=chunks) as inlined_da, + ): assert num_graph_nodes(inlined_da) < num_graph_nodes(not_inlined_da) diff --git a/xarray/tests/test_backends_api.py b/xarray/tests/test_backends_api.py index befc4cbaf04..d4f8b7ed31d 100644 --- a/xarray/tests/test_backends_api.py +++ b/xarray/tests/test_backends_api.py @@ -79,11 +79,13 @@ def explicit_chunks(chunks, shape): # Emulate `dask.array.core.normalize_chunks` but for simpler inputs. return tuple( ( - (size // chunk) * (chunk,) - + ((size % chunk,) if size % chunk or size == 0 else ()) + ( + (size // chunk) * (chunk,) + + ((size % chunk,) if size % chunk or size == 0 else ()) + ) + if isinstance(chunk, Number) + else chunk ) - if isinstance(chunk, Number) - else chunk for chunk, size in zip(chunks, shape) ) diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index ab1fc316f77..4b279745d16 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -504,8 +504,7 @@ def test_constructor_multiindex(self) -> None: assert_identical(da.coords, coords) def test_constructor_custom_index(self) -> None: - class CustomIndex(Index): - ... + class CustomIndex(Index): ... coords = Coordinates( coords={"x": ("x", [1, 2, 3])}, indexes={"x": CustomIndex()} @@ -4187,9 +4186,7 @@ def test_polyfit(self, use_dask, use_datetime) -> None: xcoord = x da_raw = DataArray( - np.stack( - (10 + 1e-15 * x + 2e-28 * x**2, 30 + 2e-14 * x + 1e-29 * x**2) - ), + np.stack((10 + 1e-15 * x + 2e-28 * x**2, 30 + 2e-14 * x + 1e-29 * x**2)), dims=("d", "x"), coords={"x": xcoord, "d": [0, 1]}, ) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 77d172f00b8..cc6d583cdf6 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -675,8 +675,7 @@ def test_constructor_multiindex(self) -> None: Dataset(coords={"x": midx}) def test_constructor_custom_index(self) -> None: - class CustomIndex(Index): - ... + class CustomIndex(Index): ... coords = Coordinates( coords={"x": ("x", [1, 2, 3])}, indexes={"x": CustomIndex()} @@ -3603,8 +3602,7 @@ def test_set_xindex(self) -> None: expected_mindex = ds.set_index(x=["foo", "bar"]) assert_identical(actual_mindex, expected_mindex) - class NotAnIndex: - ... + class NotAnIndex: ... with pytest.raises(TypeError, match=".*not a subclass of xarray.Index"): ds.set_xindex("foo", NotAnIndex) # type: ignore diff --git a/xarray/tests/test_distributed.py b/xarray/tests/test_distributed.py index aa53bcf329b..d223bce2098 100644 --- a/xarray/tests/test_distributed.py +++ b/xarray/tests/test_distributed.py @@ -1,4 +1,5 @@ """ isort:skip_file """ + from __future__ import annotations import pickle diff --git a/xarray/tests/test_formatting.py b/xarray/tests/test_formatting.py index 6ed4103aef7..435daa27d60 100644 --- a/xarray/tests/test_formatting.py +++ b/xarray/tests/test_formatting.py @@ -627,8 +627,9 @@ def test_repr_file_collapsed(tmp_path) -> None: arr_to_store = xr.DataArray(np.arange(300, dtype=np.int64), dims="test") arr_to_store.to_netcdf(tmp_path / "test.nc", engine="netcdf4") - with xr.open_dataarray(tmp_path / "test.nc") as arr, xr.set_options( - display_expand_data=False + with ( + xr.open_dataarray(tmp_path / "test.nc") as arr, + xr.set_options(display_expand_data=False), ): actual = repr(arr) expected = dedent( diff --git a/xarray/tests/test_namedarray.py b/xarray/tests/test_namedarray.py index 20652f4cc3b..2a3faf32b85 100644 --- a/xarray/tests/test_namedarray.py +++ b/xarray/tests/test_namedarray.py @@ -391,8 +391,7 @@ def _new( dims: _DimsLike | Default = ..., data: duckarray[Any, _DType] = ..., attrs: _AttrsLike | Default = ..., - ) -> Variable[Any, _DType]: - ... + ) -> Variable[Any, _DType]: ... @overload def _new( @@ -400,8 +399,7 @@ def _new( dims: _DimsLike | Default = ..., data: Default = ..., attrs: _AttrsLike | Default = ..., - ) -> Variable[_ShapeType_co, _DType_co]: - ... + ) -> Variable[_ShapeType_co, _DType_co]: ... def _new( self, @@ -454,8 +452,7 @@ def _new( dims: _DimsLike | Default = ..., data: duckarray[Any, _DType] = ..., attrs: _AttrsLike | Default = ..., - ) -> Variable[Any, _DType]: - ... + ) -> Variable[Any, _DType]: ... @overload def _new( @@ -463,8 +460,7 @@ def _new( dims: _DimsLike | Default = ..., data: Default = ..., attrs: _AttrsLike | Default = ..., - ) -> Variable[_ShapeType_co, _DType_co]: - ... + ) -> Variable[_ShapeType_co, _DType_co]: ... def _new( self, diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index 21915a9a17c..0bd454866c3 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -1635,15 +1635,19 @@ def test_raw_numpy_methods(self, func, unit, error, dtype): variable = xr.Variable("x", array) args = [ - item * unit - if isinstance(item, (int, float, list)) and func.name != "item" - else item + ( + item * unit + if isinstance(item, (int, float, list)) and func.name != "item" + else item + ) for item in func.args ] kwargs = { - key: value * unit - if isinstance(value, (int, float, list)) and func.name != "item" - else value + key: ( + value * unit + if isinstance(value, (int, float, list)) and func.name != "item" + else value + ) for key, value in func.kwargs.items() } @@ -1654,15 +1658,19 @@ def test_raw_numpy_methods(self, func, unit, error, dtype): return converted_args = [ - strip_units(convert_units(item, {None: unit_registry.m})) - if func.name != "item" - else item + ( + strip_units(convert_units(item, {None: unit_registry.m})) + if func.name != "item" + else item + ) for item in args ] converted_kwargs = { - key: strip_units(convert_units(value, {None: unit_registry.m})) - if func.name != "item" - else value + key: ( + strip_units(convert_units(value, {None: unit_registry.m})) + if func.name != "item" + else value + ) for key, value in kwargs.items() } @@ -1974,9 +1982,11 @@ def test_masking(self, func, unit, error, dtype): strip_units( convert_units( other, - {None: base_unit} - if is_compatible(base_unit, unit) - else {None: None}, + ( + {None: base_unit} + if is_compatible(base_unit, unit) + else {None: None} + ), ) ), ), diff --git a/xarray/tutorial.py b/xarray/tutorial.py index 498dd791dd0..82bb3940b98 100644 --- a/xarray/tutorial.py +++ b/xarray/tutorial.py @@ -5,6 +5,7 @@ * building tutorials in the documentation. """ + from __future__ import annotations import os diff --git a/xarray/util/generate_aggregations.py b/xarray/util/generate_aggregations.py index e436cd42335..3462af28663 100644 --- a/xarray/util/generate_aggregations.py +++ b/xarray/util/generate_aggregations.py @@ -12,6 +12,7 @@ while replacing the doctests. """ + import collections import textwrap from dataclasses import dataclass, field @@ -347,9 +348,11 @@ def generate_method(self, method): template_kwargs = dict( obj=self.datastructure.name, method=method.name, - keep_attrs="\n keep_attrs: bool | None = None," - if self.has_keep_attrs - else "", + keep_attrs=( + "\n keep_attrs: bool | None = None," + if self.has_keep_attrs + else "" + ), kw_only="\n *," if has_kw_only else "", ) diff --git a/xarray/util/generate_ops.py b/xarray/util/generate_ops.py index f9aa69d983b..ee4dd68b3ba 100644 --- a/xarray/util/generate_ops.py +++ b/xarray/util/generate_ops.py @@ -6,6 +6,7 @@ python xarray/util/generate_ops.py > xarray/core/_typed_ops.py """ + # Note: the comments in https://github.com/pydata/xarray/pull/4904 provide some # background to some of the design choices made here. diff --git a/xarray/util/print_versions.py b/xarray/util/print_versions.py index 4b7f28cb34b..4c715437588 100755 --- a/xarray/util/print_versions.py +++ b/xarray/util/print_versions.py @@ -1,4 +1,5 @@ """Utility functions for printing version information.""" + import importlib import locale import os