diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 74d77e2f2ca..eaabf5160b6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,22 +13,12 @@ repos: - id: mixed-line-ending - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: 'v0.2.0' + rev: 'v0.2.2' 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: 24.1.1 - hooks: - - id: black-jupyter - - repo: https://github.com/keewis/blackdoc - rev: v0.3.9 - hooks: - - id: blackdoc - exclude: "generate_aggregations.py" - additional_dependencies: ["black==24.1.1"] - - id: blackdoc-autoupdate-black + - id: ruff-format + types_or: [ python, pyi, jupyter ] - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.8.0 hooks: diff --git a/asv_bench/benchmarks/__init__.py b/asv_bench/benchmarks/__init__.py index aa600c88003..47eb44ee54f 100644 --- a/asv_bench/benchmarks/__init__.py +++ b/asv_bench/benchmarks/__init__.py @@ -67,7 +67,6 @@ def _skip_slow(): >>> from . import _skip_slow >>> def time_something_slow(): ... pass - ... >>> time_something.setup = _skip_slow """ if os.environ.get("ASV_SKIP_SLOW", "0") == "1": diff --git a/doc/examples/apply_ufunc_vectorize_1d.ipynb b/doc/examples/apply_ufunc_vectorize_1d.ipynb index c2ab7271873..de8aa397869 100644 --- a/doc/examples/apply_ufunc_vectorize_1d.ipynb +++ b/doc/examples/apply_ufunc_vectorize_1d.ipynb @@ -460,7 +460,8 @@ "interped = interped.rename({\"new_lat\": \"lat\"})\n", "interped[\"lat\"] = newlat # need to add this manually\n", "xr.testing.assert_allclose(\n", - " expected.transpose(*interped.dims), interped # order of dims is different\n", + " expected.transpose(*interped.dims),\n", + " interped, # order of dims is different\n", ")\n", "interped" ] diff --git a/pyproject.toml b/pyproject.toml index 4b5f6b31a43..573161582ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -86,8 +86,8 @@ exclude_lines = ["pragma: no cover", "if TYPE_CHECKING"] [tool.mypy] enable_error_code = "redundant-self" exclude = [ - 'xarray/util/generate_.*\.py', - 'xarray/datatree_/.*\.py', + 'xarray/util/generate_.*\.py', + 'xarray/datatree_/.*\.py', ] files = "xarray" show_error_codes = true @@ -247,7 +247,6 @@ reportMissingTypeStubs = false [tool.ruff] builtins = ["ellipsis"] extend-exclude = [ - "doc", "_typed_ops.pyi", ] target-version = "py39" @@ -256,6 +255,9 @@ target-version = "py39" # E402: module level import not at top of file # E501: line too long - let black worry about that # E731: do not assign a lambda expression, use a def +extend-safe-fixes = [ + "TID252", # absolute imports +] ignore = [ "E402", "E501", @@ -269,9 +271,6 @@ select = [ "I", # isort "UP", # Pyupgrade ] -extend-safe-fixes = [ - "TID252", # absolute imports -] [tool.ruff.lint.per-file-ignores] # don't enforce absolute imports @@ -284,6 +283,13 @@ known-first-party = ["xarray"] # Disallow all relative imports. ban-relative-imports = "all" +[tool.ruff.lint.pydocstyle] +convention = "numpy" + +[tool.ruff.format] +docstring-code-format = true +preview = false + [tool.pytest.ini_options] addopts = ["--strict-config", "--strict-markers"] filterwarnings = [ diff --git a/xarray/backends/api.py b/xarray/backends/api.py index d3026a535e2..18347cafe1e 100644 --- a/xarray/backends/api.py +++ b/xarray/backends/api.py @@ -1132,7 +1132,8 @@ def to_netcdf( *, multifile: Literal[True], invalid_netcdf: bool = False, -) -> tuple[ArrayWriter, AbstractDataStore]: ... +) -> tuple[ArrayWriter, AbstractDataStore]: + ... # path=None writes to bytes @@ -1149,7 +1150,8 @@ def to_netcdf( compute: bool = True, multifile: Literal[False] = False, invalid_netcdf: bool = False, -) -> bytes: ... +) -> bytes: + ... # compute=False returns dask.Delayed @@ -1167,7 +1169,8 @@ def to_netcdf( compute: Literal[False], multifile: Literal[False] = False, invalid_netcdf: bool = False, -) -> Delayed: ... +) -> Delayed: + ... # default return None @@ -1184,7 +1187,8 @@ 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 @@ -1202,7 +1206,8 @@ 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 @@ -1220,7 +1225,8 @@ def to_netcdf( compute: bool = False, multifile: bool = False, invalid_netcdf: bool = False, -) -> tuple[ArrayWriter, AbstractDataStore] | Delayed | None: ... +) -> tuple[ArrayWriter, AbstractDataStore] | Delayed | None: + ... # Any @@ -1237,7 +1243,8 @@ 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( @@ -1671,7 +1678,8 @@ 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 @@ -1694,7 +1702,8 @@ 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/common.py b/xarray/backends/common.py index 7d3cc00a52d..3c39e931ca2 100644 --- a/xarray/backends/common.py +++ b/xarray/backends/common.py @@ -235,13 +235,10 @@ def load(self): For example:: class SuffixAppendingDataStore(AbstractDataStore): - def load(self): variables, attributes = AbstractDataStore.load(self) - variables = {'%s_suffix' % k: v - for k, v in variables.items()} - attributes = {'%s_suffix' % k: v - for k, v in attributes.items()} + variables = {"%s_suffix" % k: v for k, v in variables.items()} + attributes = {"%s_suffix" % k: v for k, v in attributes.items()} return variables, attributes This function will be called anytime variables or attributes diff --git a/xarray/backends/locks.py b/xarray/backends/locks.py index 69cef309b45..045ee522fa8 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/backends/plugins.py b/xarray/backends/plugins.py index a62ca6c9862..6c7d7e10055 100644 --- a/xarray/backends/plugins.py +++ b/xarray/backends/plugins.py @@ -82,7 +82,7 @@ def backends_dict_from_pkg( def set_missing_parameters( - backend_entrypoints: dict[str, type[BackendEntrypoint]] + backend_entrypoints: dict[str, type[BackendEntrypoint]], ) -> None: for _, backend in backend_entrypoints.items(): if backend.open_dataset_parameters is None: @@ -91,7 +91,7 @@ def set_missing_parameters( def sort_backends( - backend_entrypoints: dict[str, type[BackendEntrypoint]] + backend_entrypoints: dict[str, type[BackendEntrypoint]], ) -> dict[str, type[BackendEntrypoint]]: ordered_backends_entrypoints = {} for be_name in STANDARD_BACKENDS_ORDER: diff --git a/xarray/core/_typed_ops.py b/xarray/core/_typed_ops.py index c1748e322c2..cb172223293 100644 --- a/xarray/core/_typed_ops.py +++ b/xarray/core/_typed_ops.py @@ -455,163 +455,199 @@ 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 13e3400d170..0339bddb904 100644 --- a/xarray/core/alignment.py +++ b/xarray/core/alignment.py @@ -599,7 +599,8 @@ def align( indexes=None, exclude: str | Iterable[Hashable] = frozenset(), fill_value=dtypes.NA, -) -> tuple[T_Obj1]: ... +) -> tuple[T_Obj1]: + ... @overload @@ -613,7 +614,8 @@ def align( indexes=None, exclude: str | Iterable[Hashable] = frozenset(), fill_value=dtypes.NA, -) -> tuple[T_Obj1, T_Obj2]: ... +) -> tuple[T_Obj1, T_Obj2]: + ... @overload @@ -628,7 +630,8 @@ 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 @@ -644,7 +647,8 @@ 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 @@ -661,7 +665,8 @@ 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 @@ -672,7 +677,8 @@ def align( indexes=None, exclude: str | Iterable[Hashable] = frozenset(), fill_value=dtypes.NA, -) -> tuple[T_Alignable, ...]: ... +) -> tuple[T_Alignable, ...]: + ... def align( @@ -1090,13 +1096,15 @@ 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 @@ -1107,7 +1115,8 @@ def broadcast( /, *, exclude: str | Iterable[Hashable] | None = None, -) -> tuple[T_Obj1, T_Obj2, T_Obj3]: ... +) -> tuple[T_Obj1, T_Obj2, T_Obj3]: + ... @overload @@ -1119,7 +1128,8 @@ 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 @@ -1132,13 +1142,15 @@ 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/common.py b/xarray/core/common.py index cf2b4063202..d5d08fa8aa6 100644 --- a/xarray/core/common.py +++ b/xarray/core/common.py @@ -200,10 +200,12 @@ 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. @@ -758,13 +760,10 @@ def pipe( >>> def adder(data, arg): ... return data + arg - ... >>> def div(data, arg): ... return data / arg - ... >>> def sub_mult(data, sub_arg, mult_arg): ... return (data * mult_arg) - sub_arg - ... >>> x.pipe(adder, 2) Size: 96B Dimensions: (lat: 2, lon: 2) @@ -1501,7 +1500,8 @@ def full_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> DataArray: ... +) -> DataArray: + ... @overload @@ -1513,7 +1513,8 @@ def full_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Dataset: ... +) -> Dataset: + ... @overload @@ -1525,7 +1526,8 @@ def full_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Variable: ... +) -> Variable: + ... @overload @@ -1537,7 +1539,8 @@ 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 @@ -1549,7 +1552,8 @@ 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( @@ -1790,7 +1794,8 @@ def zeros_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> DataArray: ... +) -> DataArray: + ... @overload @@ -1801,7 +1806,8 @@ def zeros_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Dataset: ... +) -> Dataset: + ... @overload @@ -1812,7 +1818,8 @@ def zeros_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Variable: ... +) -> Variable: + ... @overload @@ -1823,7 +1830,8 @@ 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 @@ -1834,7 +1842,8 @@ 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( @@ -1927,7 +1936,8 @@ def ones_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> DataArray: ... +) -> DataArray: + ... @overload @@ -1938,7 +1948,8 @@ def ones_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Dataset: ... +) -> Dataset: + ... @overload @@ -1949,7 +1960,8 @@ def ones_like( chunks: T_Chunks = None, chunked_array_type: str | None = None, from_array_kwargs: dict[str, Any] | None = None, -) -> Variable: ... +) -> Variable: + ... @overload @@ -1960,7 +1972,8 @@ 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 @@ -1971,7 +1984,8 @@ 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 f29f6c4dd35..72bd8fe59b4 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -2050,25 +2050,29 @@ 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 @@ -2076,7 +2080,8 @@ def polyval( coord: Dataset | DataArray, coeffs: Dataset | DataArray, degree_dim: Hashable = "degree", -) -> Dataset | DataArray: ... +) -> Dataset | DataArray: + ... def polyval( @@ -2245,19 +2250,23 @@ 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 d95cbccd36a..8411e136cc2 100644 --- a/xarray/core/concat.py +++ b/xarray/core/concat.py @@ -42,7 +42,8 @@ def concat( fill_value: object = dtypes.NA, join: JoinOptions = "outer", combine_attrs: CombineAttrsOptions = "override", -) -> T_Dataset: ... +) -> T_Dataset: + ... @overload @@ -56,7 +57,8 @@ 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 c00fe1a9e67..84dc6eeaa22 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -972,7 +972,8 @@ def reset_coords( names: Dims = None, *, drop: Literal[False] = False, - ) -> Dataset: ... + ) -> Dataset: + ... @overload def reset_coords( @@ -980,7 +981,8 @@ def reset_coords( names: Dims = None, *, drop: Literal[True], - ) -> Self: ... + ) -> Self: + ... @_deprecate_positional_args("v2023.10.0") def reset_coords( @@ -1524,7 +1526,7 @@ def sel( Do not try to assign values when using any of the indexing methods ``isel`` or ``sel``:: - da = xr.DataArray([0, 1, 2, 3], dims=['x']) + da = xr.DataArray([0, 1, 2, 3], dims=["x"]) # DO NOT do this da.isel(x=[0, 1, 2])[1] = -1 @@ -3914,7 +3916,8 @@ def to_netcdf( unlimited_dims: Iterable[Hashable] | None = None, compute: bool = True, invalid_netcdf: bool = False, - ) -> bytes: ... + ) -> bytes: + ... # compute=False returns dask.Delayed @overload @@ -3930,7 +3933,8 @@ def to_netcdf( *, compute: Literal[False], invalid_netcdf: bool = False, - ) -> Delayed: ... + ) -> Delayed: + ... # default return None @overload @@ -3945,7 +3949,8 @@ 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 @@ -3961,7 +3966,8 @@ def to_netcdf( unlimited_dims: Iterable[Hashable] | None = None, compute: bool = True, invalid_netcdf: bool = False, - ) -> Delayed | None: ... + ) -> Delayed | None: + ... def to_netcdf( self, @@ -4110,7 +4116,8 @@ 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 @@ -4130,7 +4137,8 @@ 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, @@ -5484,7 +5492,6 @@ def map_blocks( ... gb = da.groupby(groupby_type) ... clim = gb.mean(dim="time") ... return gb - clim - ... >>> time = xr.cftime_range("1990-01", "1992-01", freq="ME") >>> month = xr.DataArray(time.month, coords={"time": time}, dims=["time"]) >>> np.random.seed(123) @@ -6310,7 +6317,6 @@ def curvefit( >>> rng = np.random.default_rng(seed=0) >>> def exp_decay(t, time_constant, amplitude): ... return np.exp(-t / time_constant) * amplitude - ... >>> t = np.arange(11) >>> da = xr.DataArray( ... np.stack( diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 884e302b8be..93b4f189dd0 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -289,7 +289,6 @@ def _maybe_chunk( chunked_array_type: str | ChunkManagerEntrypoint | None = None, from_array_kwargs=None, ): - from xarray.namedarray.daskmanager import DaskManager if chunks is not None: @@ -1522,11 +1521,13 @@ 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,7 +2152,8 @@ def to_netcdf( unlimited_dims: Iterable[Hashable] | None = None, compute: bool = True, invalid_netcdf: bool = False, - ) -> bytes: ... + ) -> bytes: + ... # compute=False returns dask.Delayed @overload @@ -2167,7 +2169,8 @@ def to_netcdf( *, compute: Literal[False], invalid_netcdf: bool = False, - ) -> Delayed: ... + ) -> Delayed: + ... # default return None @overload @@ -2182,7 +2185,8 @@ 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 @@ -2198,7 +2202,8 @@ def to_netcdf( unlimited_dims: Iterable[Hashable] | None = None, compute: bool = True, invalid_netcdf: bool = False, - ) -> Delayed | None: ... + ) -> Delayed | None: + ... def to_netcdf( self, @@ -2329,7 +2334,8 @@ 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 @@ -2351,7 +2357,8 @@ 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, @@ -8726,7 +8733,6 @@ def map_blocks( ... gb = da.groupby(groupby_type) ... clim = gb.mean(dim="time") ... return gb - clim - ... >>> time = xr.cftime_range("1990-01", "1992-01", freq="ME") >>> month = xr.DataArray(time.month, coords={"time": time}, dims=["time"]) >>> np.random.seed(123) diff --git a/xarray/core/extensions.py b/xarray/core/extensions.py index efe00718a79..be7f0701a6b 100644 --- a/xarray/core/extensions.py +++ b/xarray/core/extensions.py @@ -105,7 +105,6 @@ def register_dataset_accessor(name): ... def plot(self): ... # plot this array's data on a map, e.g., using Cartopy ... pass - ... Back in an interactive IPython session: diff --git a/xarray/core/groupby.py b/xarray/core/groupby.py index ed6c74bc262..9d122687386 100644 --- a/xarray/core/groupby.py +++ b/xarray/core/groupby.py @@ -273,7 +273,9 @@ def to_array(self) -> DataArray: T_Group = Union["T_DataArray", "IndexVariable", _DummyGroup] -def _ensure_1d(group: T_Group, obj: T_Xarray) -> tuple[ +def _ensure_1d( + group: T_Group, obj: T_Xarray +) -> tuple[ T_Group, T_Xarray, Hashable | None, diff --git a/xarray/core/indexes.py b/xarray/core/indexes.py index e71c4a6f073..338d842177d 100644 --- a/xarray/core/indexes.py +++ b/xarray/core/indexes.py @@ -1735,7 +1735,7 @@ def indexes_equal( def indexes_all_equal( - elements: Sequence[tuple[Index, dict[Hashable, Variable]]] + elements: Sequence[tuple[Index, dict[Hashable, Variable]]], ) -> bool: """Check if indexes are all equal. diff --git a/xarray/core/options.py b/xarray/core/options.py index 18e3484e9c4..b8888ed2f79 100644 --- a/xarray/core/options.py +++ b/xarray/core/options.py @@ -257,7 +257,6 @@ class set_options: >>> ds = xr.Dataset({"x": np.arange(1000)}) >>> with xr.set_options(display_width=40): ... print(ds) - ... Size: 8kB Dimensions: (x: 1000) Coordinates: diff --git a/xarray/core/parallel.py b/xarray/core/parallel.py index 41311497f8b..8d295b521d7 100644 --- a/xarray/core/parallel.py +++ b/xarray/core/parallel.py @@ -296,7 +296,6 @@ def map_blocks( ... gb = da.groupby(groupby_type) ... clim = gb.mean(dim="time") ... return gb - clim - ... >>> time = xr.cftime_range("1990-01", "1992-01", freq="ME") >>> month = xr.DataArray(time.month, coords={"time": time}, dims=["time"]) >>> np.random.seed(123) @@ -372,7 +371,8 @@ def _wrapper( # ChainMap wants MutableMapping, but xindexes is Mapping merged_indexes = collections.ChainMap( - expected["indexes"], merged_coordinates.xindexes # type: ignore[arg-type] + expected["indexes"], + merged_coordinates.xindexes, # type: ignore[arg-type] ) expected_index = merged_indexes.get(name, None) if expected_index is not None and not index.equals(expected_index): diff --git a/xarray/core/resample.py b/xarray/core/resample.py index 3bb158acfdb..cadd25b4e6d 100644 --- a/xarray/core/resample.py +++ b/xarray/core/resample.py @@ -183,7 +183,9 @@ def _interpolate(self, kind="linear") -> T_Xarray: # https://github.com/python/mypy/issues/9031 -class DataArrayResample(Resample["DataArray"], DataArrayGroupByBase, DataArrayResampleAggregations): # type: ignore[misc] +class DataArrayResample( + Resample["DataArray"], DataArrayGroupByBase, DataArrayResampleAggregations +): # type: ignore[misc] """DataArrayGroupBy object specialized to time resampling operations over a specified dimension """ @@ -336,7 +338,9 @@ def asfreq(self) -> DataArray: # https://github.com/python/mypy/issues/9031 -class DatasetResample(Resample["Dataset"], DatasetGroupByBase, DatasetResampleAggregations): # type: ignore[misc] +class DatasetResample( + Resample["Dataset"], DatasetGroupByBase, DatasetResampleAggregations +): # type: ignore[misc] """DatasetGroupBy object specialized to resampling a specified dimension""" def map( diff --git a/xarray/core/types.py b/xarray/core/types.py index 410cf3de00b..8c3164c52fa 100644 --- a/xarray/core/types.py +++ b/xarray/core/types.py @@ -102,13 +102,16 @@ 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, @@ -119,22 +122,27 @@ 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 9b527622e40..0e6a352c0ac 100644 --- a/xarray/core/utils.py +++ b/xarray/core/utils.py @@ -470,10 +470,12 @@ 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() @@ -857,7 +859,8 @@ def parse_dims( *, check_exists: bool = True, replace_none: Literal[True] = True, -) -> tuple[Hashable, ...]: ... +) -> tuple[Hashable, ...]: + ... @overload @@ -867,7 +870,8 @@ def parse_dims( *, check_exists: bool = True, replace_none: Literal[False], -) -> tuple[Hashable, ...] | None | ellipsis: ... +) -> tuple[Hashable, ...] | None | ellipsis: + ... def parse_dims( @@ -918,7 +922,8 @@ def parse_ordered_dims( *, check_exists: bool = True, replace_none: Literal[True] = True, -) -> tuple[Hashable, ...]: ... +) -> tuple[Hashable, ...]: + ... @overload @@ -928,7 +933,8 @@ def parse_ordered_dims( *, check_exists: bool = True, replace_none: Literal[False], -) -> tuple[Hashable, ...] | None | ellipsis: ... +) -> tuple[Hashable, ...] | None | ellipsis: + ... def parse_ordered_dims( @@ -1010,10 +1016,12 @@ 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/namedarray/_array_api.py b/xarray/namedarray/_array_api.py index 977d011c685..2b8c485d6e9 100644 --- a/xarray/namedarray/_array_api.py +++ b/xarray/namedarray/_array_api.py @@ -88,7 +88,8 @@ def astype( def imag( - x: NamedArray[_ShapeType, np.dtype[_SupportsImag[_ScalarType]]], / # type: ignore[type-var] + x: NamedArray[_ShapeType, np.dtype[_SupportsImag[_ScalarType]]], + /, # type: ignore[type-var] ) -> NamedArray[_ShapeType, np.dtype[_ScalarType]]: """ Returns the imaginary component of a complex number for each element x_i of the @@ -120,7 +121,8 @@ def imag( def real( - x: NamedArray[_ShapeType, np.dtype[_SupportsReal[_ScalarType]]], / # type: ignore[type-var] + x: NamedArray[_ShapeType, np.dtype[_SupportsReal[_ScalarType]]], + /, # type: ignore[type-var] ) -> NamedArray[_ShapeType, np.dtype[_ScalarType]]: """ Returns the real component of a complex number for each element x_i of the diff --git a/xarray/namedarray/_typing.py b/xarray/namedarray/_typing.py index b715973814f..96bb813bc69 100644 --- a/xarray/namedarray/_typing.py +++ b/xarray/namedarray/_typing.py @@ -56,7 +56,8 @@ class Default(Enum): @runtime_checkable class _SupportsDType(Protocol[_DType_co]): @property - def dtype(self) -> _DType_co: ... + def dtype(self) -> _DType_co: + ... _DTypeLike = Union[ @@ -101,12 +102,14 @@ 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 @@ -118,10 +121,12 @@ 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 @@ -137,10 +142,12 @@ 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, @@ -150,17 +157,21 @@ def __getitem__( | 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 @@ -170,7 +181,8 @@ 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 @@ -180,13 +192,16 @@ 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 @@ -203,9 +218,11 @@ def __getitem__( _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__: @@ -230,7 +247,8 @@ class _chunkedarray( """ @property - def chunks(self) -> _Chunks: ... + def chunks(self) -> _Chunks: + ... @runtime_checkable @@ -244,7 +262,8 @@ class _chunkedarrayfunction( """ @property - def chunks(self) -> _Chunks: ... + def chunks(self) -> _Chunks: + ... @runtime_checkable @@ -258,7 +277,8 @@ class _chunkedarrayapi( """ @property - def chunks(self) -> _Chunks: ... + def chunks(self) -> _Chunks: + ... # NamedArray can most likely use both __array_function__ and __array_namespace__: @@ -279,7 +299,8 @@ 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,7 +313,8 @@ class _sparsearrayfunction( Corresponds to np.ndarray. """ - def todense(self) -> np.ndarray[Any, _DType_co]: ... + def todense(self) -> np.ndarray[Any, _DType_co]: + ... @runtime_checkable @@ -305,7 +327,8 @@ 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 29722690437..e5e5fbb760c 100644 --- a/xarray/namedarray/core.py +++ b/xarray/namedarray/core.py @@ -102,7 +102,8 @@ def _new( dims: _DimsLike | Default = ..., data: duckarray[_ShapeType, _DType] = ..., attrs: _AttrsLike | Default = ..., -) -> NamedArray[_ShapeType, _DType]: ... +) -> NamedArray[_ShapeType, _DType]: + ... @overload @@ -111,7 +112,8 @@ def _new( dims: _DimsLike | Default = ..., data: Default = ..., attrs: _AttrsLike | Default = ..., -) -> NamedArray[_ShapeType_co, _DType_co]: ... +) -> NamedArray[_ShapeType_co, _DType_co]: + ... def _new( @@ -159,7 +161,8 @@ def from_array( dims: _DimsLike, data: duckarray[_ShapeType, _DType], attrs: _AttrsLike = ..., -) -> NamedArray[_ShapeType, _DType]: ... +) -> NamedArray[_ShapeType, _DType]: + ... @overload @@ -167,7 +170,8 @@ def from_array( dims: _DimsLike, data: ArrayLike, attrs: _AttrsLike = ..., -) -> NamedArray[Any, Any]: ... +) -> NamedArray[Any, Any]: + ... def from_array( @@ -279,7 +283,8 @@ def _new( dims: _DimsLike | Default = ..., data: duckarray[_ShapeType, _DType] = ..., attrs: _AttrsLike | Default = ..., - ) -> NamedArray[_ShapeType, _DType]: ... + ) -> NamedArray[_ShapeType, _DType]: + ... @overload def _new( @@ -287,7 +292,8 @@ def _new( dims: _DimsLike | Default = ..., data: Default = ..., attrs: _AttrsLike | Default = ..., - ) -> NamedArray[_ShapeType_co, _DType_co]: ... + ) -> NamedArray[_ShapeType_co, _DType_co]: + ... def _new( self, @@ -652,10 +658,12 @@ 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/namedarray/parallelcompat.py b/xarray/namedarray/parallelcompat.py index c6263bff4ff..80ba0bcf078 100644 --- a/xarray/namedarray/parallelcompat.py +++ b/xarray/namedarray/parallelcompat.py @@ -29,17 +29,21 @@ class ChunkedArrayMixinProtocol(Protocol): - def rechunk(self, chunks: Any, **kwargs: Any) -> Any: ... + def rechunk(self, chunks: Any, **kwargs: Any) -> Any: + ... @property - def dtype(self) -> np.dtype[Any]: ... + def dtype(self) -> np.dtype[Any]: + ... @property - def chunks(self) -> _NormalizedChunks: ... + def chunks(self) -> _NormalizedChunks: + ... def compute( self, *data: Any, **kwargs: Any - ) -> tuple[np.ndarray[Any, _DType_co], ...]: ... + ) -> tuple[np.ndarray[Any, _DType_co], ...]: + ... T_ChunkedArray = TypeVar("T_ChunkedArray", bound=ChunkedArrayMixinProtocol) diff --git a/xarray/plot/accessor.py b/xarray/plot/accessor.py index 9db4ae4e3f7..203bae2691f 100644 --- a/xarray/plot/accessor.py +++ b/xarray/plot/accessor.py @@ -77,7 +77,8 @@ 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( @@ -103,7 +104,8 @@ def line( add_legend: bool = True, _labels: bool = True, **kwargs: Any, - ) -> FacetGrid[DataArray]: ... + ) -> FacetGrid[DataArray]: + ... @overload def line( @@ -129,7 +131,8 @@ 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]: @@ -145,7 +148,8 @@ 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( @@ -157,7 +161,8 @@ def step( row: Hashable, # wrap -> FacetGrid col: Hashable | None = None, **kwargs: Any, - ) -> FacetGrid[DataArray]: ... + ) -> FacetGrid[DataArray]: + ... @overload def step( @@ -169,7 +174,8 @@ 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]: @@ -213,7 +219,8 @@ def scatter( # type: ignore[misc,unused-ignore] # None is hashable :( extend=None, levels=None, **kwargs, - ) -> PathCollection: ... + ) -> PathCollection: + ... @overload def scatter( @@ -253,7 +260,8 @@ def scatter( extend=None, levels=None, **kwargs, - ) -> FacetGrid[DataArray]: ... + ) -> FacetGrid[DataArray]: + ... @overload def scatter( @@ -293,7 +301,8 @@ 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]: @@ -336,7 +345,8 @@ 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( @@ -375,7 +385,8 @@ def imshow( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> FacetGrid[DataArray]: ... + ) -> FacetGrid[DataArray]: + ... @overload def imshow( @@ -414,7 +425,8 @@ 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]: @@ -457,7 +469,8 @@ 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( @@ -496,7 +509,8 @@ def contour( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> FacetGrid[DataArray]: ... + ) -> FacetGrid[DataArray]: + ... @overload def contour( @@ -535,7 +549,8 @@ 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]: @@ -578,7 +593,8 @@ 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( @@ -617,7 +633,8 @@ def contourf( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> FacetGrid[DataArray]: ... + ) -> FacetGrid[DataArray]: + ... @overload def contourf( @@ -656,7 +673,8 @@ 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]: @@ -699,7 +717,8 @@ 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( @@ -738,7 +757,8 @@ def pcolormesh( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> FacetGrid[DataArray]: ... + ) -> FacetGrid[DataArray]: + ... @overload def pcolormesh( @@ -777,7 +797,8 @@ 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]: @@ -820,7 +841,8 @@ def surface( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> Poly3DCollection: ... + ) -> Poly3DCollection: + ... @overload def surface( @@ -859,7 +881,8 @@ def surface( ylim: tuple[float, float] | None = None, norm: Normalize | None = None, **kwargs: Any, - ) -> FacetGrid: ... + ) -> FacetGrid: + ... @overload def surface( @@ -898,7 +921,8 @@ 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: @@ -961,7 +985,8 @@ def scatter( # type: ignore[misc,unused-ignore] # None is hashable :( extend=None, levels=None, **kwargs: Any, - ) -> PathCollection: ... + ) -> PathCollection: + ... @overload def scatter( @@ -1001,7 +1026,8 @@ def scatter( extend=None, levels=None, **kwargs: Any, - ) -> FacetGrid[Dataset]: ... + ) -> FacetGrid[Dataset]: + ... @overload def scatter( @@ -1041,7 +1067,8 @@ 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]: @@ -1081,7 +1108,8 @@ def quiver( # type: ignore[misc,unused-ignore] # None is hashable :( extend=None, cmap=None, **kwargs: Any, - ) -> Quiver: ... + ) -> Quiver: + ... @overload def quiver( @@ -1117,7 +1145,8 @@ def quiver( extend=None, cmap=None, **kwargs: Any, - ) -> FacetGrid[Dataset]: ... + ) -> FacetGrid[Dataset]: + ... @overload def quiver( @@ -1153,7 +1182,8 @@ 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]: @@ -1193,7 +1223,8 @@ def streamplot( # type: ignore[misc,unused-ignore] # None is hashable :( extend=None, cmap=None, **kwargs: Any, - ) -> LineCollection: ... + ) -> LineCollection: + ... @overload def streamplot( @@ -1229,7 +1260,8 @@ def streamplot( extend=None, cmap=None, **kwargs: Any, - ) -> FacetGrid[Dataset]: ... + ) -> FacetGrid[Dataset]: + ... @overload def streamplot( @@ -1265,7 +1297,8 @@ 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 8386161bf29..a82ed63c68f 100644 --- a/xarray/plot/dataarray_plot.py +++ b/xarray/plot/dataarray_plot.py @@ -333,7 +333,8 @@ def line( # type: ignore[misc,unused-ignore] # None is hashable :( add_legend: bool = True, _labels: bool = True, **kwargs: Any, -) -> list[Line3D]: ... +) -> list[Line3D]: + ... @overload @@ -360,7 +361,8 @@ def line( add_legend: bool = True, _labels: bool = True, **kwargs: Any, -) -> FacetGrid[T_DataArray]: ... +) -> FacetGrid[T_DataArray]: + ... @overload @@ -387,7 +389,8 @@ 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 @@ -541,7 +544,8 @@ 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 @@ -554,7 +558,8 @@ def step( row: Hashable, # wrap -> FacetGrid col: Hashable | None = None, **kwargs: Any, -) -> FacetGrid[DataArray]: ... +) -> FacetGrid[DataArray]: + ... @overload @@ -567,7 +572,8 @@ def step( row: Hashable | None = None, col: Hashable, # wrap -> FacetGrid **kwargs: Any, -) -> FacetGrid[DataArray]: ... +) -> FacetGrid[DataArray]: + ... def step( @@ -1140,7 +1146,8 @@ def scatter( # type: ignore[misc,unused-ignore] # None is hashable :( extend: ExtendOptions = None, levels: ArrayLike | None = None, **kwargs, -) -> PathCollection: ... +) -> PathCollection: + ... @overload @@ -1181,7 +1188,8 @@ def scatter( extend: ExtendOptions = None, levels: ArrayLike | None = None, **kwargs, -) -> FacetGrid[T_DataArray]: ... +) -> FacetGrid[T_DataArray]: + ... @overload @@ -1222,7 +1230,8 @@ def scatter( extend: ExtendOptions = None, levels: ArrayLike | None = None, **kwargs, -) -> FacetGrid[T_DataArray]: ... +) -> FacetGrid[T_DataArray]: + ... @_plot1d @@ -1689,7 +1698,8 @@ def imshow( # type: ignore[misc,unused-ignore] # None is hashable :( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> AxesImage: ... +) -> AxesImage: + ... @overload @@ -1729,7 +1739,8 @@ def imshow( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: ... +) -> FacetGrid[T_DataArray]: + ... @overload @@ -1769,7 +1780,8 @@ def imshow( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: ... +) -> FacetGrid[T_DataArray]: + ... @_plot2d @@ -1905,7 +1917,8 @@ def contour( # type: ignore[misc,unused-ignore] # None is hashable :( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> QuadContourSet: ... +) -> QuadContourSet: + ... @overload @@ -1945,7 +1958,8 @@ def contour( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: ... +) -> FacetGrid[T_DataArray]: + ... @overload @@ -1985,7 +1999,8 @@ def contour( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: ... +) -> FacetGrid[T_DataArray]: + ... @_plot2d @@ -2038,7 +2053,8 @@ def contourf( # type: ignore[misc,unused-ignore] # None is hashable :( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> QuadContourSet: ... +) -> QuadContourSet: + ... @overload @@ -2078,7 +2094,8 @@ def contourf( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: ... +) -> FacetGrid[T_DataArray]: + ... @overload @@ -2118,7 +2135,8 @@ def contourf( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: ... +) -> FacetGrid[T_DataArray]: + ... @_plot2d @@ -2171,7 +2189,8 @@ def pcolormesh( # type: ignore[misc,unused-ignore] # None is hashable :( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> QuadMesh: ... +) -> QuadMesh: + ... @overload @@ -2211,7 +2230,8 @@ def pcolormesh( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: ... +) -> FacetGrid[T_DataArray]: + ... @overload @@ -2251,7 +2271,8 @@ def pcolormesh( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: ... +) -> FacetGrid[T_DataArray]: + ... @_plot2d @@ -2355,7 +2376,8 @@ def surface( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> Poly3DCollection: ... +) -> Poly3DCollection: + ... @overload @@ -2395,7 +2417,8 @@ def surface( ylim: ArrayLike | None = None, norm: Normalize | None = None, **kwargs: Any, -) -> FacetGrid[T_DataArray]: ... +) -> FacetGrid[T_DataArray]: + ... @overload @@ -2435,7 +2458,8 @@ 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 edc2bf43629..a3ca201eec4 100644 --- a/xarray/plot/dataset_plot.py +++ b/xarray/plot/dataset_plot.py @@ -354,7 +354,8 @@ def quiver( # type: ignore[misc,unused-ignore] # None is hashable :( extend: ExtendOptions = None, cmap: str | Colormap | None = None, **kwargs: Any, -) -> Quiver: ... +) -> Quiver: + ... @overload @@ -391,7 +392,8 @@ def quiver( extend: ExtendOptions = None, cmap: str | Colormap | None = None, **kwargs: Any, -) -> FacetGrid[Dataset]: ... +) -> FacetGrid[Dataset]: + ... @overload @@ -428,7 +430,8 @@ def quiver( extend: ExtendOptions = None, cmap: str | Colormap | None = None, **kwargs: Any, -) -> FacetGrid[Dataset]: ... +) -> FacetGrid[Dataset]: + ... @_dsplot @@ -505,7 +508,8 @@ def streamplot( # type: ignore[misc,unused-ignore] # None is hashable :( extend: ExtendOptions = None, cmap: str | Colormap | None = None, **kwargs: Any, -) -> LineCollection: ... +) -> LineCollection: + ... @overload @@ -542,7 +546,8 @@ def streamplot( extend: ExtendOptions = None, cmap: str | Colormap | None = None, **kwargs: Any, -) -> FacetGrid[Dataset]: ... +) -> FacetGrid[Dataset]: + ... @overload @@ -579,7 +584,8 @@ def streamplot( extend: ExtendOptions = None, cmap: str | Colormap | None = None, **kwargs: Any, -) -> FacetGrid[Dataset]: ... +) -> FacetGrid[Dataset]: + ... @_dsplot @@ -780,7 +786,8 @@ def scatter( # type: ignore[misc,unused-ignore] # None is hashable :( extend: ExtendOptions = None, levels: ArrayLike | None = None, **kwargs: Any, -) -> PathCollection: ... +) -> PathCollection: + ... @overload @@ -821,7 +828,8 @@ def scatter( extend: ExtendOptions = None, levels: ArrayLike | None = None, **kwargs: Any, -) -> FacetGrid[DataArray]: ... +) -> FacetGrid[DataArray]: + ... @overload @@ -862,7 +870,8 @@ 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 804e1cfd795..6f1a5a68cfe 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -974,7 +974,7 @@ def legend_elements( This is useful for obtaining a legend for a `~.Axes.scatter` plot; e.g.:: - scatter = plt.scatter([1, 2, 3], [4, 5, 6], c=[7, 2, 3]) + scatter = plt.scatter([1, 2, 3], [4, 5, 6], c=[7, 2, 3]) plt.legend(*scatter.legend_elements()) creates three legend elements, one for each color with the numerical @@ -1291,14 +1291,16 @@ 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 @@ -1443,10 +1445,12 @@ 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: """ @@ -1468,10 +1472,12 @@ 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/strategies.py b/xarray/testing/strategies.py index c5a7afdf54e..d08cbc0b584 100644 --- a/xarray/testing/strategies.py +++ b/xarray/testing/strategies.py @@ -36,7 +36,8 @@ def __call__( *, shape: "_ShapeLike", dtype: "_DTypeLikeNested", - ) -> st.SearchStrategy[T_DuckArray]: ... + ) -> st.SearchStrategy[T_DuckArray]: + ... def supported_dtypes() -> st.SearchStrategy[np.dtype]: @@ -367,7 +368,8 @@ def unique_subset_of( *, min_size: int = 0, max_size: Union[int, None] = None, -) -> st.SearchStrategy[Sequence[Hashable]]: ... +) -> st.SearchStrategy[Sequence[Hashable]]: + ... @overload @@ -376,7 +378,8 @@ 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_cftime_offsets.py b/xarray/tests/test_cftime_offsets.py index 0110afe40ac..4ca5a426948 100644 --- a/xarray/tests/test_cftime_offsets.py +++ b/xarray/tests/test_cftime_offsets.py @@ -1689,7 +1689,6 @@ def test_new_to_legacy_freq_anchored(year_alias, n): ), ) def test_legacy_to_new_freq_pd_freq_passthrough(freq, expected): - result = _legacy_to_new_freq(freq) assert result == expected @@ -1715,7 +1714,6 @@ def test_legacy_to_new_freq_pd_freq_passthrough(freq, expected): ), ) def test_new_to_legacy_freq_pd_freq_passthrough(freq, expected): - result = _new_to_legacy_freq(freq) assert result == expected diff --git a/xarray/tests/test_coordinates.py b/xarray/tests/test_coordinates.py index 68ce55b05da..2d9855c662c 100644 --- a/xarray/tests/test_coordinates.py +++ b/xarray/tests/test_coordinates.py @@ -60,7 +60,9 @@ def test_init_index_error(self) -> None: Coordinates(indexes={"x": idx}) with pytest.raises(TypeError, match=".* is not an `xarray.indexes.Index`"): - Coordinates(coords={"x": ("x", [1, 2, 3])}, indexes={"x": "not_an_xarray_index"}) # type: ignore + Coordinates( + coords={"x": ("x", [1, 2, 3])}, indexes={"x": "not_an_xarray_index"} + ) # type: ignore def test_init_dim_sizes_conflict(self) -> None: with pytest.raises(ValueError): diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index 2829fd7d49c..f6964f3ad8c 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -510,7 +510,8 @@ 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()} diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 4937fc5f3a3..21cf9aa8f52 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -676,7 +676,8 @@ 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()} @@ -3610,7 +3611,8 @@ 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_formatting.py b/xarray/tests/test_formatting.py index 6923d26b79a..288a8ed6901 100644 --- a/xarray/tests/test_formatting.py +++ b/xarray/tests/test_formatting.py @@ -865,7 +865,6 @@ def test_display_nbytes() -> None: def test_array_repr_dtypes(): - # These dtypes are expected to be represented similarly # on Ubuntu, macOS and Windows environments of the CI. # Unsigned integer could be used as easy replacements @@ -975,7 +974,6 @@ def test_array_repr_dtypes(): reason="Default numpy's dtypes vary according to OS", ) def test_array_repr_dtypes_unix() -> None: - # Signed integer dtypes ds = xr.DataArray(np.array([0]), dims="x") @@ -1011,7 +1009,6 @@ def test_array_repr_dtypes_unix() -> None: reason="Default numpy's dtypes vary according to OS", ) def test_array_repr_dtypes_on_windows() -> None: - # Integer dtypes ds = xr.DataArray(np.array([0]), dims="x") diff --git a/xarray/tests/test_namedarray.py b/xarray/tests/test_namedarray.py index 2a3faf32b85..20652f4cc3b 100644 --- a/xarray/tests/test_namedarray.py +++ b/xarray/tests/test_namedarray.py @@ -391,7 +391,8 @@ def _new( dims: _DimsLike | Default = ..., data: duckarray[Any, _DType] = ..., attrs: _AttrsLike | Default = ..., - ) -> Variable[Any, _DType]: ... + ) -> Variable[Any, _DType]: + ... @overload def _new( @@ -399,7 +400,8 @@ def _new( dims: _DimsLike | Default = ..., data: Default = ..., attrs: _AttrsLike | Default = ..., - ) -> Variable[_ShapeType_co, _DType_co]: ... + ) -> Variable[_ShapeType_co, _DType_co]: + ... def _new( self, @@ -452,7 +454,8 @@ def _new( dims: _DimsLike | Default = ..., data: duckarray[Any, _DType] = ..., attrs: _AttrsLike | Default = ..., - ) -> Variable[Any, _DType]: ... + ) -> Variable[Any, _DType]: + ... @overload def _new( @@ -460,7 +463,8 @@ 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_treenode.py b/xarray/tests/test_treenode.py index b0e737bd317..02f2abd6262 100644 --- a/xarray/tests/test_treenode.py +++ b/xarray/tests/test_treenode.py @@ -297,7 +297,6 @@ def test_levelorderiter(self): class TestAncestry: - def test_parents(self): _, leaf_f = create_test_tree() expected = ["e", "b", "a"]