Skip to content

Commit

Permalink
partial revert
Browse files Browse the repository at this point in the history
  • Loading branch information
crusaderky committed Jan 15, 2024
1 parent b8e6ab7 commit 39f8c81
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
4 changes: 3 additions & 1 deletion xarray/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ def copy(
DsCompatible = Union["Dataset", "DaCompatible"]
GroupByCompatible = Union["Dataset", "DataArray"]

Dims = Union[Hashable, Collection[Hashable], None] # Note: Hashable include ellipsis
# Don't change to Hashable | Collection[Hashable]
# Read: https://github.com/pydata/xarray/issues/6142
Dims = Dims = Union[str, Collection[Hashable], ellipsis, None]

# FYI in some cases we don't allow `None`, which this doesn't take account of.
T_ChunkDim: TypeAlias = Union[int, Literal["auto"], None, tuple[int, ...]]
Expand Down
16 changes: 7 additions & 9 deletions xarray/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
Mapping,
MutableMapping,
MutableSet,
Sequence,
ValuesView,
)
from enum import Enum
Expand Down Expand Up @@ -1042,14 +1041,11 @@ def parse_dims(
if replace_none:
return all_dims
return dim
if isinstance(dim, Collection) and not isinstance(dim, str):
dim = tuple(dim)
else:
if isinstance(dim, str):
dim = (dim,)

if check_exists:
_check_dims(set(dim), set(all_dims))
return dim
return tuple(dim)


@overload
Expand Down Expand Up @@ -1083,14 +1079,16 @@ def parse_ordered_dims(
) -> tuple[Hashable, ...] | None | ellipsis:
"""Parse one or more dimensions.
A single dimension must be always a str, multiple dimensions
can be Hashables. This supports e.g. using a tuple as a dimension.
An ellipsis ("...") in a sequence of dimensions will be
replaced with all remaining dimensions. This only makes sense when
the input is a sequence and not e.g. a set.
Parameters
----------
dim : Hashable or ... (or Sequence thereof), or None
Dimension(s) to parse. If ... appears in a Sequence
dim : str, Sequence of Hashable or "...", "..." or None
Dimension(s) to parse. If "..." appears in a Sequence
it always gets replaced with all remaining dims
all_dims : tuple of Hashable
All possible dimensions.
Expand All @@ -1104,7 +1102,7 @@ def parse_ordered_dims(
parsed_dims : tuple of Hashable
Input dimensions as a tuple.
"""
if isinstance(dim, Sequence) and not isinstance(dim, str) and ... in dim:
if dim is not None and dim is not ... and not isinstance(dim, str) and ... in dim:
dims_set: set[Hashable | ellipsis] = set(dim)
all_dims_set = set(all_dims)
if check_exists:
Expand Down
1 change: 0 additions & 1 deletion xarray/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ def test_infix_dims_errors(supplied, all_):
["dim", "expected"],
[
pytest.param("a", ("a",), id="str"),
pytest.param(1, (1,), id="non_str_hashable"),
pytest.param(["a", "b"], ("a", "b"), id="list_of_str"),
pytest.param(["a", 1], ("a", 1), id="list_mixed"),
pytest.param(["a", ...], ("a", ...), id="list_with_ellipsis"),
Expand Down

0 comments on commit 39f8c81

Please sign in to comment.