Skip to content

Change concat dims to be Hashable #6121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions xarray/core/concat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from typing import (
TYPE_CHECKING,
Dict,
Expand All @@ -12,6 +14,7 @@
)

import pandas as pd
from typing_extensions import Literal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why tests didn't fail here, but unconditionally importing from typing_extensions causes import xarray to fail on Python >=3.8.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#6159 should fix this error. You might get errors for python 3.7 instead though, see #5892.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only run nightly with latest Python, so that's fine. I'll deal with the Py 3.7 removals another day...


from . import dtypes, utils
from .alignment import align
Expand All @@ -24,14 +27,19 @@
from .dataarray import DataArray
from .dataset import Dataset

compat_options = Literal[
"identical", "equals", "broadcast_equals", "no_conflicts", "override"
]
concat_options = Literal["all", "minimal", "different"]


@overload
def concat(
objs: Iterable["Dataset"],
dim: Union[str, "DataArray", pd.Index],
data_vars: Union[str, List[str]] = "all",
coords: Union[str, List[str]] = "different",
compat: str = "equals",
dim: Hashable | "DataArray" | pd.Index,
data_vars: concat_options | List[Hashable] = "all",
coords: concat_options | List[Hashable] = "different",
compat: compat_options = "equals",
positions: Optional[Iterable[int]] = None,
fill_value: object = dtypes.NA,
join: str = "outer",
Expand All @@ -43,10 +51,10 @@ def concat(
@overload
def concat(
objs: Iterable["DataArray"],
dim: Union[str, "DataArray", pd.Index],
data_vars: Union[str, List[str]] = "all",
coords: Union[str, List[str]] = "different",
compat: str = "equals",
dim: Hashable | "DataArray" | pd.Index,
data_vars: concat_options | List[Hashable] = "all",
coords: concat_options | List[Hashable] = "different",
compat: compat_options = "equals",
positions: Optional[Iterable[int]] = None,
fill_value: object = dtypes.NA,
join: str = "outer",
Expand Down Expand Up @@ -74,14 +82,14 @@ def concat(
xarray objects to concatenate together. Each object is expected to
consist of variables and coordinates with matching shapes except for
along the concatenated dimension.
dim : str or DataArray or pandas.Index
dim : Hashable or DataArray or pandas.Index
Name of the dimension to concatenate along. This can either be a new
dimension name, in which case it is added along axis=0, or an existing
dimension name, in which case the location of the dimension is
unchanged. If dimension is provided as a DataArray or Index, its name
is used as the dimension to concatenate along and the values are added
as a coordinate.
data_vars : {"minimal", "different", "all"} or list of str, optional
data_vars : {"minimal", "different", "all"} or list of Hashable, optional
These data variables will be concatenated together:
* "minimal": Only data variables in which the dimension already
appears are included.
Expand All @@ -91,11 +99,11 @@ def concat(
load the data payload of data variables into memory if they are not
already loaded.
* "all": All data variables will be concatenated.
* list of str: The listed data variables will be concatenated, in
* list of dims: The listed data variables will be concatenated, in
addition to the "minimal" data variables.

If objects are DataArrays, data_vars must be "all".
coords : {"minimal", "different", "all"} or list of str, optional
coords : {"minimal", "different", "all"} or list of Hashable, optional
These coordinate variables will be concatenated together:
* "minimal": Only coordinates in which the dimension already appears
are included.
Expand All @@ -106,7 +114,7 @@ def concat(
loaded.
* "all": All coordinate variables will be concatenated, except
those corresponding to other dimensions.
* list of str: The listed coordinate variables will be concatenated,
* list of Hashable: The listed coordinate variables will be concatenated,
in addition to the "minimal" coordinates.
compat : {"identical", "equals", "broadcast_equals", "no_conflicts", "override"}, optional
String indicating how to compare non-concatenated variables of the same name for
Expand Down
Loading