diff --git a/xarray/backends/chunks.py b/xarray/backends/chunks.py index 64630455e8b..f17f5375976 100644 --- a/xarray/backends/chunks.py +++ b/xarray/backends/chunks.py @@ -141,7 +141,7 @@ def build_grid_chunks( if region is None: region = slice(0, size) - region_start = region.start if region.start else 0 + region_start = region.start or 0 # Generate the zarr chunks inside the region of this dim chunks_on_region = [chunk_size - (region_start % chunk_size)] chunks_on_region.extend([chunk_size] * ((size - chunks_on_region[0]) // chunk_size)) @@ -224,7 +224,7 @@ def validate_grid_chunks_alignment( ) ) - interval_start = interval.start if interval.start else 0 + interval_start = interval.start or 0 if len(var_chunks) > 1: # The first border size is the amount of data that needs to be updated on the @@ -247,7 +247,7 @@ def validate_grid_chunks_alignment( ) if not allow_partial_chunks: - region_stop = interval.stop if interval.stop else size + region_stop = interval.stop or size error_on_last_chunk = base_error.format( var_chunk_pos=len(var_chunks) - 1, diff --git a/xarray/backends/pydap_.py b/xarray/backends/pydap_.py index 301ea430c4c..73b719f8260 100644 --- a/xarray/backends/pydap_.py +++ b/xarray/backends/pydap_.py @@ -158,11 +158,12 @@ def get_variables(self): except AttributeError: from pydap.model import GroupType - _vars = list(self.ds.keys()) - # check the key is a BaseType or GridType - for var in _vars: - if isinstance(self.ds[var], GroupType): - _vars.remove(var) + _vars = [ + var + for var in self.ds.keys() + # check the key is not a BaseType or GridType + if not isinstance(self.ds[var], GroupType) + ] return FrozenDict((k, self.open_store_variable(self.ds[k])) for k in _vars) def get_attrs(self): diff --git a/xarray/backends/zarr.py b/xarray/backends/zarr.py index 54ff419b2f2..fff07063964 100644 --- a/xarray/backends/zarr.py +++ b/xarray/backends/zarr.py @@ -1184,7 +1184,7 @@ def set_variables( # with chunk boundaries, then no synchronization is required." # TODO: incorporate synchronizer to allow writes from multiple dask # threads - shape = zarr_shape if zarr_shape else v.shape + shape = zarr_shape or v.shape validate_grid_chunks_alignment( nd_var_chunks=v.chunks, enc_chunks=encoding["chunks"], @@ -1545,7 +1545,7 @@ def guess_can_open( ) -> bool: if isinstance(filename_or_obj, str | os.PathLike): _, ext = os.path.splitext(filename_or_obj) - return ext in {".zarr"} + return ext == ".zarr" return False diff --git a/xarray/coding/times.py b/xarray/coding/times.py index e6bc8ca59bd..d1cc36558fa 100644 --- a/xarray/coding/times.py +++ b/xarray/coding/times.py @@ -246,7 +246,7 @@ def build_pattern( ] pattern_list = [] for sep, name, sub_pattern in pieces: - pattern_list.append((sep if sep else "") + named(name, sub_pattern)) + pattern_list.append((sep or "") + named(name, sub_pattern)) # TODO: allow timezone offsets? return "^" + trailing_optional(pattern_list) + "$" diff --git a/xarray/computation/nanops.py b/xarray/computation/nanops.py index 17c60b6f663..6475ad890a2 100644 --- a/xarray/computation/nanops.py +++ b/xarray/computation/nanops.py @@ -112,7 +112,7 @@ def _nanmean_ddof_object(ddof, value, axis=None, dtype=None, **kwargs): # As dtype inference is impossible for object dtype, we assume float # https://github.com/dask/dask/issues/3162 if dtype is None and value.dtype.kind == "O": - dtype = value.dtype if value.dtype.kind in ["cf"] else float + dtype = float data = np.sum(value, axis=axis, dtype=dtype, **kwargs) data = data / (valid_count - ddof) diff --git a/xarray/core/accessor_str.py b/xarray/core/accessor_str.py index 06570ceba3a..0bab92963a5 100644 --- a/xarray/core/accessor_str.py +++ b/xarray/core/accessor_str.py @@ -349,7 +349,7 @@ def f(x, iind): islice = slice(-1, None) if iind == -1 else slice(iind, iind + 1) item = x[islice] - return item if item else default + return item or default return self._apply(func=f, func_args=(i,)) diff --git a/xarray/core/common.py b/xarray/core/common.py index 6181aa6a8c1..a190766b01a 100644 --- a/xarray/core/common.py +++ b/xarray/core/common.py @@ -1782,7 +1782,7 @@ def _full_like_variable( other.shape, fill_value, dtype=dtype, - chunks=chunks if chunks else other.data.chunks, + chunks=chunks or other.data.chunks, **from_array_kwargs, ) else: diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index c13d33872b6..0bfb0b7ab1c 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -498,7 +498,7 @@ def _replace( self, variable: Variable | None = None, coords=None, - name: Hashable | None | Default = _default, + name: Hashable | Default | None = _default, attrs=_default, indexes=None, ) -> Self: @@ -520,7 +520,7 @@ def _replace( def _replace_maybe_drop_dims( self, variable: Variable, - name: Hashable | None | Default = _default, + name: Hashable | Default | None = _default, ) -> Self: if self.sizes == variable.sizes: coords = self._coords.copy() @@ -581,7 +581,7 @@ def _to_temp_dataset(self) -> Dataset: return self._to_dataset_whole(name=_THIS_ARRAY, shallow_copy=False) def _from_temp_dataset( - self, dataset: Dataset, name: Hashable | None | Default = _default + self, dataset: Dataset, name: Hashable | Default | None = _default ) -> Self: variable = dataset._variables.pop(_THIS_ARRAY) coords = dataset._variables @@ -2609,8 +2609,8 @@ def swap_dims( def expand_dims( self, - dim: None | Hashable | Sequence[Hashable] | Mapping[Any, Any] = None, - axis: None | int | Sequence[int] = None, + dim: Hashable | Sequence[Hashable] | Mapping[Any, Any] | None = None, + axis: int | Sequence[int] | None = None, create_index_for_new_dim: bool = True, **dim_kwargs: Any, ) -> Self: diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 95e6f516403..d090f3019cf 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -791,9 +791,9 @@ def _replace( variables: dict[Hashable, Variable] | None = None, coord_names: set[Hashable] | None = None, dims: dict[Any, int] | None = None, - attrs: dict[Hashable, Any] | None | Default = _default, + attrs: dict[Hashable, Any] | Default | None = _default, indexes: dict[Hashable, Index] | None = None, - encoding: dict | None | Default = _default, + encoding: dict | Default | None = _default, inplace: bool = False, ) -> Self: """Fastpath constructor for internal use. @@ -840,7 +840,7 @@ def _replace_with_new_dims( self, variables: dict[Hashable, Variable], coord_names: set | None = None, - attrs: dict[Hashable, Any] | None | Default = _default, + attrs: dict[Hashable, Any] | Default | None = _default, indexes: dict[Hashable, Index] | None = None, inplace: bool = False, ) -> Self: @@ -855,7 +855,7 @@ def _replace_vars_and_dims( variables: dict[Hashable, Variable], coord_names: set | None = None, dims: dict[Hashable, int] | None = None, - attrs: dict[Hashable, Any] | None | Default = _default, + attrs: dict[Hashable, Any] | Default | None = _default, inplace: bool = False, ) -> Self: """Deprecated version of _replace_with_new_dims(). @@ -4350,8 +4350,8 @@ def swap_dims( def expand_dims( self, - dim: None | Hashable | Sequence[Hashable] | Mapping[Any, Any] = None, - axis: None | int | Sequence[int] = None, + dim: Hashable | Sequence[Hashable] | Mapping[Any, Any] | None = None, + axis: int | Sequence[int] | None = None, create_index_for_new_dim: bool = True, **dim_kwargs: Any, ) -> Self: diff --git a/xarray/core/datatree.py b/xarray/core/datatree.py index 734927fd3d1..81873635dae 100644 --- a/xarray/core/datatree.py +++ b/xarray/core/datatree.py @@ -347,9 +347,9 @@ def _replace( # type: ignore[override] variables: dict[Hashable, Variable] | None = None, coord_names: set[Hashable] | None = None, dims: dict[Any, int] | None = None, - attrs: dict[Hashable, Any] | None | Default = _default, + attrs: dict[Hashable, Any] | Default | None = _default, indexes: dict[Hashable, Index] | None = None, - encoding: dict | None | Default = _default, + encoding: dict | Default | None = _default, inplace: bool = False, ) -> Dataset: """ diff --git a/xarray/core/datatree_mapping.py b/xarray/core/datatree_mapping.py index 6262c7f19cd..050a412005d 100644 --- a/xarray/core/datatree_mapping.py +++ b/xarray/core/datatree_mapping.py @@ -42,7 +42,7 @@ def map_over_datasets( def map_over_datasets( - func: Callable[..., Dataset | None | tuple[Dataset | None, ...]], + func: Callable[..., Dataset | tuple[Dataset | None, ...] | None], *args: Any, kwargs: Mapping[str, Any] | None = None, ) -> DataTree | tuple[DataTree, ...]: @@ -106,7 +106,7 @@ def map_over_datasets( # Walk all trees simultaneously, applying func to all nodes that lie in same position in different trees # We don't know which arguments are DataTrees so we zip all arguments together as iterables # Store tuples of results in a dict because we don't yet know how many trees we need to rebuild to return - out_data_objects: dict[str, Dataset | None | tuple[Dataset | None, ...]] = {} + out_data_objects: dict[str, Dataset | tuple[Dataset | None, ...] | None] = {} tree_args = [arg for arg in args if isinstance(arg, DataTree)] name = result_name(tree_args) @@ -171,7 +171,7 @@ def add_note(err: BaseException, msg: str) -> None: def _check_single_set_return_values(path_to_node: str, obj: Any) -> int | None: """Check types returned from single evaluation of func, and return number of return values received from func.""" - if isinstance(obj, None | Dataset): + if isinstance(obj, Dataset | None): return None # no need to pack results if not isinstance(obj, tuple) or not all( diff --git a/xarray/core/extension_array.py b/xarray/core/extension_array.py index 7cc9db96d0d..d85f7e66b55 100644 --- a/xarray/core/extension_array.py +++ b/xarray/core/extension_array.py @@ -83,7 +83,7 @@ def __extension_duck_array__reshape( @dataclass(frozen=True) -class PandasExtensionArray(Generic[T_ExtensionArray], NDArrayMixin): +class PandasExtensionArray(NDArrayMixin, Generic[T_ExtensionArray]): """NEP-18 compliant wrapper for pandas extension arrays. Parameters diff --git a/xarray/core/types.py b/xarray/core/types.py index 01b908cb723..d51ba59120e 100644 --- a/xarray/core/types.py +++ b/xarray/core/types.py @@ -214,7 +214,7 @@ def copy( # FYI in some cases we don't allow `None`, which this doesn't take account of. # FYI the `str` is for a size string, e.g. "16MB", supported by dask. -T_ChunkDim: TypeAlias = str | int | Literal["auto"] | None | tuple[int, ...] # noqa: PYI051 +T_ChunkDim: TypeAlias = str | int | Literal["auto"] | tuple[int, ...] | None # noqa: PYI051 T_ChunkDimFreq: TypeAlias = Union["TimeResampler", T_ChunkDim] T_ChunksFreq: TypeAlias = T_ChunkDim | Mapping[Any, T_ChunkDimFreq] # We allow the tuple form of this (though arguably we could transition to named dims only) diff --git a/xarray/core/utils.py b/xarray/core/utils.py index 9c1e1fd99bf..562706a1ac0 100644 --- a/xarray/core/utils.py +++ b/xarray/core/utils.py @@ -897,7 +897,7 @@ def parse_dims_as_tuple( *, check_exists: bool = True, replace_none: Literal[False], -) -> tuple[Hashable, ...] | None | EllipsisType: ... +) -> tuple[Hashable, ...] | EllipsisType | None: ... def parse_dims_as_tuple( @@ -906,7 +906,7 @@ def parse_dims_as_tuple( *, check_exists: bool = True, replace_none: bool = True, -) -> tuple[Hashable, ...] | None | EllipsisType: +) -> tuple[Hashable, ...] | EllipsisType | None: """Parse one or more dimensions. A single dimension must be always a str, multiple dimensions @@ -958,7 +958,7 @@ def parse_dims_as_set( *, check_exists: bool = True, replace_none: Literal[False], -) -> set[Hashable] | None | EllipsisType: ... +) -> set[Hashable] | EllipsisType | None: ... def parse_dims_as_set( @@ -967,7 +967,7 @@ def parse_dims_as_set( *, check_exists: bool = True, replace_none: bool = True, -) -> set[Hashable] | None | EllipsisType: +) -> set[Hashable] | EllipsisType | None: """Like parse_dims_as_tuple, but returning a set instead of a tuple.""" # TODO: Consider removing parse_dims_as_tuple? if dim is None or dim is ...: @@ -999,7 +999,7 @@ def parse_ordered_dims( *, check_exists: bool = True, replace_none: Literal[False], -) -> tuple[Hashable, ...] | None | EllipsisType: ... +) -> tuple[Hashable, ...] | EllipsisType | None: ... def parse_ordered_dims( @@ -1008,7 +1008,7 @@ def parse_ordered_dims( *, check_exists: bool = True, replace_none: bool = True, -) -> tuple[Hashable, ...] | None | EllipsisType: +) -> tuple[Hashable, ...] | EllipsisType | None: """Parse one or more dimensions. A single dimension must be always a str, multiple dimensions @@ -1086,7 +1086,7 @@ def __get__(self, obj: None, cls) -> type[_Accessor]: ... @overload def __get__(self, obj: object, cls) -> _Accessor: ... - def __get__(self, obj: None | object, cls) -> type[_Accessor] | _Accessor: + def __get__(self, obj: object | None, cls) -> type[_Accessor] | _Accessor: if obj is None: return self._accessor @@ -1287,7 +1287,7 @@ def attempt_import(module: str) -> ModuleType: matplotlib="for plotting", hypothesis="for the `xarray.testing.strategies` submodule", ) - package_name = module.split(".")[0] # e.g. "zarr" from "zarr.storage" + package_name = module.split(".", maxsplit=1)[0] # e.g. "zarr" from "zarr.storage" install_name = install_mapping.get(package_name, package_name) reason = package_purpose.get(package_name, "") try: diff --git a/xarray/namedarray/_typing.py b/xarray/namedarray/_typing.py index 2dba06a5d44..342f72e54f1 100644 --- a/xarray/namedarray/_typing.py +++ b/xarray/namedarray/_typing.py @@ -78,7 +78,7 @@ def dtype(self) -> _DType_co: ... _NormalizedChunks = tuple[tuple[int, ...], ...] # FYI in some cases we don't allow `None`, which this doesn't take account of. # # FYI the `str` is for a size string, e.g. "16MB", supported by dask. -T_ChunkDim: TypeAlias = str | int | Literal["auto"] | None | tuple[int, ...] # noqa: PYI051 +T_ChunkDim: TypeAlias = str | int | Literal["auto"] | tuple[int, ...] | None # noqa: PYI051 # We allow the tuple form of this (though arguably we could transition to named dims only) T_Chunks: TypeAlias = T_ChunkDim | Mapping[Any, T_ChunkDim] diff --git a/xarray/plot/facetgrid.py b/xarray/plot/facetgrid.py index 719b1fde619..e4f330ba27e 100644 --- a/xarray/plot/facetgrid.py +++ b/xarray/plot/facetgrid.py @@ -796,7 +796,7 @@ def _get_largest_lims(self) -> dict[str, tuple[float, float]]: # Find the plot with the largest xlim values: lower, upper = lims_largest[axis] for ax in self.axs.flat: - get_lim: None | Callable[[], tuple[float, float]] = getattr( + get_lim: Callable[[], tuple[float, float]] | None = getattr( ax, f"get_{axis}lim", None ) if get_lim: @@ -862,15 +862,15 @@ def _set_labels( for ax in axes: getattr(ax, f"set_{axis}label")(label, **kwargs) - def set_xlabels(self, label: None | str = None, **kwargs: Any) -> None: + def set_xlabels(self, label: str | None = None, **kwargs: Any) -> None: """Label the x axis on the bottom row of the grid.""" self._set_labels("x", self._bottom_axes, label, **kwargs) - def set_ylabels(self, label: None | str = None, **kwargs: Any) -> None: + def set_ylabels(self, label: str | None = None, **kwargs: Any) -> None: """Label the y axis on the left column of the grid.""" self._set_labels("y", self._left_axes, label, **kwargs) - def set_zlabels(self, label: None | str = None, **kwargs: Any) -> None: + def set_zlabels(self, label: str | None = None, **kwargs: Any) -> None: """Label the z axis.""" self._set_labels("z", self._left_axes, label, **kwargs) diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index dd47df703b5..ec526d55c26 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -955,7 +955,7 @@ def _process_cmap_cbar_kwargs( cmap_kwargs = { "plot_data": data, "levels": levels, - "cmap": colors if colors else cmap, + "cmap": colors or cmap, "filled": func.__name__ != "contour", } @@ -1326,7 +1326,7 @@ def _parse_size( def _parse_size( data: DataArray | None, norm: tuple[float | None, float | None, bool] | Normalize | None, -) -> None | pd.Series: +) -> pd.Series | None: import matplotlib as mpl if data is None: @@ -1591,7 +1591,7 @@ def ticks(self) -> np.ndarray | None: >>> _Normalize(a).ticks array([1, 3, 5]) """ - val: None | np.ndarray + val: np.ndarray | None if self.data_is_numeric: val = None else: @@ -1650,13 +1650,13 @@ def format(self) -> FuncFormatter: """ import matplotlib.pyplot as plt - def _func(x: Any, pos: None | Any = None): + def _func(x: Any, pos: Any | None = None): return f"{self._lookup_arr([x])[0]}" return plt.FuncFormatter(_func) @property - def func(self) -> Callable[[Any, None | Any], Any]: + def func(self) -> Callable[[Any, Any | None], Any]: """ Return a lambda function that maps self.values elements back to the original value as a numpy array. Useful with ax.legend_elements. @@ -1675,7 +1675,7 @@ def func(self) -> Callable[[Any, None | Any], Any]: array([0.5, 3. ]) """ - def _func(x: Any, pos: None | Any = None): + def _func(x: Any, pos: Any | None = None): return self._lookup_arr(x) return _func @@ -1684,8 +1684,8 @@ def _func(x: Any, pos: None | Any = None): def _determine_guide( hueplt_norm: _Normalize, sizeplt_norm: _Normalize, - add_colorbar: None | bool = None, - add_legend: None | bool = None, + add_colorbar: bool | None = None, + add_legend: bool | None = None, plotfunc_name: str | None = None, ) -> tuple[bool, bool]: if plotfunc_name == "hist": diff --git a/xarray/structure/chunks.py b/xarray/structure/chunks.py index 1afe2e6538f..281cfe278f1 100644 --- a/xarray/structure/chunks.py +++ b/xarray/structure/chunks.py @@ -138,7 +138,7 @@ def _maybe_chunk( # by providing chunks as an input to tokenize. # subtle bugs result otherwise. see GH3350 # we use str() for speed, and use the name for the final array name on the next line - token2 = tokenize(token if token else var._data, str(chunks)) + token2 = tokenize(token or var._data, str(chunks)) name2 = f"{name_prefix}{name}-{token2}" from_array_kwargs = utils.consolidate_dask_from_array_kwargs( diff --git a/xarray/structure/combine.py b/xarray/structure/combine.py index 01c14dffee4..63c3e4cc166 100644 --- a/xarray/structure/combine.py +++ b/xarray/structure/combine.py @@ -383,7 +383,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 | Sequence[str | DataArray | pd.Index | None] | None, compat: str = "no_conflicts", data_vars: str = "all", coords: str = "different", diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index b2b9ae314c4..45c169bb931 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -2920,7 +2920,7 @@ def test_reduce_keepdims(self) -> None: expected = DataArray( orig.data.mean(keepdims=True), dims=orig.dims, - coords={k: v for k, v in coords.items() if k in ["c"]}, + coords={k: v for k, v in coords.items() if k == "c"}, ) assert_equal(actual, expected) diff --git a/xarray/tests/test_datatree.py b/xarray/tests/test_datatree.py index f6d9bd76baa..beb11b5dd3d 100644 --- a/xarray/tests/test_datatree.py +++ b/xarray/tests/test_datatree.py @@ -2309,7 +2309,7 @@ class TestUFuncs: @pytest.mark.xfail(reason="__array_ufunc__ not implemented yet") def test_tree(self, create_test_datatree): dt = create_test_datatree() - expected = create_test_datatree(modify=lambda ds: np.sin(ds)) + expected = create_test_datatree(modify=np.sin) result_tree = np.sin(dt) assert_equal(result_tree, expected) diff --git a/xarray/tests/test_duck_array_ops.py b/xarray/tests/test_duck_array_ops.py index eaafe2d4536..5928581de30 100644 --- a/xarray/tests/test_duck_array_ops.py +++ b/xarray/tests/test_duck_array_ops.py @@ -587,7 +587,7 @@ def test_reduce(dim_num, dtype, dask, func, skipna, aggdim): if dask and not has_dask: pytest.skip("requires dask") - if dask and skipna is False and dtype in [np.bool_]: + if dask and skipna is False and dtype == np.bool_: pytest.skip("dask does not compute object-typed array") rtol = 1e-04 if dtype == np.float32 else 1e-05 diff --git a/xarray/tests/test_interp.py b/xarray/tests/test_interp.py index 3d6fbcf025f..7d5a9bf3db4 100644 --- a/xarray/tests/test_interp.py +++ b/xarray/tests/test_interp.py @@ -124,7 +124,7 @@ def test_interpolate_1d(method: InterpOptions, dim: str, case: int) -> None: if not has_scipy: pytest.skip("scipy is not installed.") - if not has_dask and case in [1]: + if not has_dask and case == 1: pytest.skip("dask is not installed in the environment.") da = get_example_data(case) @@ -433,7 +433,7 @@ def test_interpolate_nd_with_nan() -> None: "case", [pytest.param(0, id="no_chunk"), pytest.param(1, id="chunk_y")] ) def test_interpolate_scalar(method: InterpOptions, case: int) -> None: - if not has_dask and case in [1]: + if not has_dask and case == 1: pytest.skip("dask is not installed in the environment.") da = get_example_data(case) @@ -463,7 +463,7 @@ def func(obj, new_x): "case", [pytest.param(3, id="no_chunk"), pytest.param(4, id="chunked")] ) def test_interpolate_nd_scalar(method: InterpOptions, case: int) -> None: - if not has_dask and case in [4]: + if not has_dask and case == 4: pytest.skip("dask is not installed in the environment.") da = get_example_data(case) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index a3c7c71ce63..bfe0b81e4b6 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -235,7 +235,7 @@ def test_1d_x_y_kw(self) -> None: z = np.arange(10) da = DataArray(np.cos(z), dims=["z"], coords=[z], name="f") - xy: list[list[None | str]] = [[None, None], [None, "z"], ["z", None]] + xy: list[list[str | None]] = [[None, None], [None, "z"], ["z", None]] f, axs = plt.subplots(3, 1, squeeze=False) for aa, (x, y) in enumerate(xy): diff --git a/xarray/tests/test_rolling.py b/xarray/tests/test_rolling.py index 3d7f5657567..d93216a3ccc 100644 --- a/xarray/tests/test_rolling.py +++ b/xarray/tests/test_rolling.py @@ -341,7 +341,7 @@ def test_ndrolling_reduce( assert_allclose(actual, expected) assert actual.sizes == expected.sizes - if name in ["mean"]: + if name == "mean": # test our reimplementation of nanmean using np.nanmean expected = getattr(rolling_obj.construct({"time": "tw", "x": "xw"}), name)( ["tw", "xw"] diff --git a/xarray/tests/test_utils.py b/xarray/tests/test_utils.py index 9873b271033..0e6bbf29a45 100644 --- a/xarray/tests/test_utils.py +++ b/xarray/tests/test_utils.py @@ -300,7 +300,7 @@ def test_parse_dims_set() -> None: @pytest.mark.parametrize( "dim", [pytest.param(None, id="None"), pytest.param(..., id="ellipsis")] ) -def test_parse_dims_replace_none(dim: None | EllipsisType) -> None: +def test_parse_dims_replace_none(dim: EllipsisType | None) -> None: all_dims = ("a", "b", 1, ("b", "c")) # selection of different Hashables actual = utils.parse_dims_as_tuple(dim, all_dims, replace_none=True) assert actual == all_dims diff --git a/xarray/tutorial.py b/xarray/tutorial.py index ec832694a99..70e7fc68f7e 100644 --- a/xarray/tutorial.py +++ b/xarray/tutorial.py @@ -85,7 +85,7 @@ def _check_netcdf_engine_installed(name): def open_dataset( name: str, cache: bool = True, - cache_dir: None | str | os.PathLike = None, + cache_dir: str | os.PathLike | None = None, *, engine: T_Engine = None, **kws, @@ -216,7 +216,7 @@ def load_dataset(*args, **kwargs) -> Dataset: return ds.load() -def scatter_example_dataset(*, seed: None | int = None) -> Dataset: +def scatter_example_dataset(*, seed: int | None = None) -> Dataset: """ Create an example dataset. @@ -255,7 +255,7 @@ def scatter_example_dataset(*, seed: None | int = None) -> Dataset: def open_datatree( name: str, cache: bool = True, - cache_dir: None | str | os.PathLike = None, + cache_dir: str | os.PathLike | None = None, *, engine: T_Engine = None, **kws, pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy