Skip to content

Commit

Permalink
fix concat for axis=0 (#880)
Browse files Browse the repository at this point in the history
* fix concat for axis=0

* 'fix' mypy
  • Loading branch information
twoertwein authored Mar 2, 2024
1 parent 02abbdb commit 7dd7b6a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
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])
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

0 comments on commit 7dd7b6a

Please sign in to comment.