Skip to content

fix concat for axis=0 #880

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 2 commits into from
Mar 2, 2024
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ ci:
autofix_prs: false
repos:
- repo: https://github.com/python/black
rev: 24.1.1
rev: 24.2.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.1
rev: v0.3.0
hooks:
- id: ruff
args: [
Expand Down
5 changes: 2 additions & 3 deletions pandas-stubs/core/reshape/concat.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ from typing_extensions import Never

from pandas._typing import (
Axis,
AxisColumn,
AxisIndex,
HashableT1,
HashableT2,
Expand Down Expand Up @@ -53,7 +52,7 @@ def concat( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappin
copy: bool = ...,
) -> DataFrame: ...
@overload
def concat(
def concat( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
objs: Iterable[Series | None] | Mapping[HashableT1, Series | None],
*,
axis: AxisIndex = ...,
Expand All @@ -73,7 +72,7 @@ def concat(
| Mapping[HashableT1, Series | DataFrame | None]
),
*,
axis: AxisColumn,
axis: Axis = ...,
join: Literal["inner", "outer"] = ...,
ignore_index: bool = ...,
keys: Iterable[HashableT2] = ...,
Expand Down
12 changes: 10 additions & 2 deletions tests/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,18 @@ def test_types_concat_none() -> None:
check(
assert_type(pd.concat([None, series, df], axis=1), pd.DataFrame), pd.DataFrame
)
check(assert_type(pd.concat([None, series, df]), pd.DataFrame), pd.DataFrame)

check(assert_type(pd.concat({"a": None, "b": series}), pd.Series), pd.Series)
check(assert_type(pd.concat({"a": None, "b": df}), pd.DataFrame), pd.DataFrame)
check(
assert_type(pd.concat({"a": None, "b": series, "c": df}, axis=1), pd.DataFrame),
pd.DataFrame,
)
check(
assert_type(pd.concat({"a": None, "b": series, "c": df}), pd.DataFrame),
pd.DataFrame,
)

if TYPE_CHECKING_INVALID_USAGE:
# using assert_type as otherwise the second call would not be type-checked
Expand All @@ -77,8 +82,8 @@ def test_types_concat_none() -> None:


def test_types_concat() -> None:
s: pd.Series = pd.Series([0, 1, -10])
s2: pd.Series = pd.Series([7, -5, 10])
Copy link
Member Author

Choose a reason for hiding this comment

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

These two annotations messed mypy in the previous commit. up

s = pd.Series([0, 1, -10])
s2 = pd.Series([7, -5, 10])

check(assert_type(pd.concat([s, s2]), pd.Series), pd.Series)
check(assert_type(pd.concat([s, s2], axis=1), pd.DataFrame), pd.DataFrame)
Expand Down Expand Up @@ -166,6 +171,9 @@ def test_types_concat() -> None:
adict = {"a": df, 2: df2}
check(assert_type(pd.concat(adict), pd.DataFrame), pd.DataFrame)

data: pd.DataFrame | pd.Series = pd.Series()
check(assert_type(pd.concat([pd.DataFrame(), data]), pd.DataFrame), pd.DataFrame)


def test_concat_args() -> None:
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})
Expand Down