Skip to content

Commit 7dd7b6a

Browse files
authored
fix concat for axis=0 (#880)
* fix concat for axis=0 * 'fix' mypy
1 parent 02abbdb commit 7dd7b6a

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ ci:
33
autofix_prs: false
44
repos:
55
- repo: https://github.com/python/black
6-
rev: 24.1.1
6+
rev: 24.2.0
77
hooks:
88
- id: black
99
- repo: https://github.com/PyCQA/isort
1010
rev: 5.13.2
1111
hooks:
1212
- id: isort
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.2.1
14+
rev: v0.3.0
1515
hooks:
1616
- id: ruff
1717
args: [

pandas-stubs/core/reshape/concat.pyi

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ from typing_extensions import Never
1616

1717
from pandas._typing import (
1818
Axis,
19-
AxisColumn,
2019
AxisIndex,
2120
HashableT1,
2221
HashableT2,
@@ -53,7 +52,7 @@ def concat( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappin
5352
copy: bool = ...,
5453
) -> DataFrame: ...
5554
@overload
56-
def concat(
55+
def concat( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
5756
objs: Iterable[Series | None] | Mapping[HashableT1, Series | None],
5857
*,
5958
axis: AxisIndex = ...,
@@ -73,7 +72,7 @@ def concat(
7372
| Mapping[HashableT1, Series | DataFrame | None]
7473
),
7574
*,
76-
axis: AxisColumn,
75+
axis: Axis = ...,
7776
join: Literal["inner", "outer"] = ...,
7877
ignore_index: bool = ...,
7978
keys: Iterable[HashableT2] = ...,

tests/test_pandas.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,18 @@ def test_types_concat_none() -> None:
6262
check(
6363
assert_type(pd.concat([None, series, df], axis=1), pd.DataFrame), pd.DataFrame
6464
)
65+
check(assert_type(pd.concat([None, series, df]), pd.DataFrame), pd.DataFrame)
6566

6667
check(assert_type(pd.concat({"a": None, "b": series}), pd.Series), pd.Series)
6768
check(assert_type(pd.concat({"a": None, "b": df}), pd.DataFrame), pd.DataFrame)
6869
check(
6970
assert_type(pd.concat({"a": None, "b": series, "c": df}, axis=1), pd.DataFrame),
7071
pd.DataFrame,
7172
)
73+
check(
74+
assert_type(pd.concat({"a": None, "b": series, "c": df}), pd.DataFrame),
75+
pd.DataFrame,
76+
)
7277

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

7883

7984
def test_types_concat() -> None:
80-
s: pd.Series = pd.Series([0, 1, -10])
81-
s2: pd.Series = pd.Series([7, -5, 10])
85+
s = pd.Series([0, 1, -10])
86+
s2 = pd.Series([7, -5, 10])
8287

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

174+
data: pd.DataFrame | pd.Series = pd.Series()
175+
check(assert_type(pd.concat([pd.DataFrame(), data]), pd.DataFrame), pd.DataFrame)
176+
169177

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

0 commit comments

Comments
 (0)