Skip to content

Commit ae7e473

Browse files
authored
Fixed TYP of names argument of concat method and included test (pandas-dev#894)
* Fixed TYP of names argument of concat method and included test Pointing to the issue pandas-dev#883 * Removed the duplicate test
1 parent 9b4a5a8 commit ae7e473

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

pandas-stubs/core/reshape/concat.pyi

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def concat(
3232
ignore_index: bool = ...,
3333
keys: Iterable[HashableT2] = ...,
3434
levels: Sequence[list[HashableT3] | tuple[HashableT3, ...]] = ...,
35-
names: list[HashableT4] = ...,
35+
names: list[HashableT4] | None = ...,
3636
verify_integrity: bool = ...,
3737
sort: bool = ...,
3838
copy: bool = ...,
@@ -46,7 +46,7 @@ def concat( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappin
4646
ignore_index: bool = ...,
4747
keys: Iterable[HashableT2] = ...,
4848
levels: Sequence[list[HashableT3] | tuple[HashableT3, ...]] = ...,
49-
names: list[HashableT4] = ...,
49+
names: list[HashableT4] | None = ...,
5050
verify_integrity: bool = ...,
5151
sort: bool = ...,
5252
copy: bool = ...,
@@ -60,7 +60,7 @@ def concat( # type: ignore[overload-overlap] # pyright: ignore[reportOverlappin
6060
ignore_index: bool = ...,
6161
keys: Iterable[HashableT2] = ...,
6262
levels: Sequence[list[HashableT3] | tuple[HashableT3, ...]] = ...,
63-
names: list[HashableT4] = ...,
63+
names: list[HashableT4] | None = ...,
6464
verify_integrity: bool = ...,
6565
sort: bool = ...,
6666
copy: bool = ...,
@@ -74,7 +74,7 @@ def concat(
7474
ignore_index: bool = ...,
7575
keys: Iterable[HashableT2] = ...,
7676
levels: Sequence[list[HashableT3] | tuple[HashableT3, ...]] = ...,
77-
names: list[HashableT4] = ...,
77+
names: list[HashableT4] | None = ...,
7878
verify_integrity: bool = ...,
7979
sort: bool = ...,
8080
copy: bool = ...,
@@ -88,7 +88,7 @@ def concat( # type: ignore[overload-overlap]
8888
ignore_index: bool = ...,
8989
keys: Iterable[HashableT2] = ...,
9090
levels: Sequence[list[HashableT3] | tuple[HashableT3, ...]] = ...,
91-
names: list[HashableT4] = ...,
91+
names: list[HashableT4] | None = ...,
9292
verify_integrity: bool = ...,
9393
sort: bool = ...,
9494
copy: bool = ...,
@@ -102,7 +102,7 @@ def concat( # type: ignore[overload-overlap]
102102
ignore_index: bool = ...,
103103
keys: Iterable[HashableT2] = ...,
104104
levels: Sequence[list[HashableT3] | tuple[HashableT3, ...]] = ...,
105-
names: list[HashableT4] = ...,
105+
names: list[HashableT4] | None = ...,
106106
verify_integrity: bool = ...,
107107
sort: bool = ...,
108108
copy: bool = ...,
@@ -119,7 +119,7 @@ def concat(
119119
ignore_index: bool = ...,
120120
keys: Iterable[HashableT2] = ...,
121121
levels: Sequence[list[HashableT3] | tuple[HashableT3, ...]] = ...,
122-
names: list[HashableT4] = ...,
122+
names: list[HashableT4] | None = ...,
123123
verify_integrity: bool = ...,
124124
sort: bool = ...,
125125
copy: bool = ...,

tests/test_pandas.py

+32
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ def test_types_concat() -> None:
9898
),
9999
pd.Series,
100100
)
101+
check(
102+
assert_type(
103+
pd.concat([s, s2], keys=["first", "second"], names=None),
104+
pd.Series,
105+
),
106+
pd.Series,
107+
)
101108

102109
# Depends on the axis
103110
check(
@@ -140,6 +147,13 @@ def test_types_concat() -> None:
140147
),
141148
pd.DataFrame,
142149
)
150+
check(
151+
assert_type(
152+
pd.concat([df, df2], keys=["first", "second"], names=None),
153+
pd.DataFrame,
154+
),
155+
pd.DataFrame,
156+
)
143157

144158
check(
145159
assert_type(
@@ -189,6 +203,12 @@ def test_concat_args() -> None:
189203
),
190204
pd.DataFrame,
191205
)
206+
check(
207+
assert_type(
208+
pd.concat([df, df2], keys=["df1", "df2"], names=None), pd.DataFrame
209+
),
210+
pd.DataFrame,
211+
)
192212
check(
193213
assert_type(
194214
pd.concat([df, df2], keys=["df1", "df2"], names=[pd.Timedelta(1, "D")]),
@@ -248,6 +268,18 @@ def test_concat_args() -> None:
248268
),
249269
pd.DataFrame,
250270
)
271+
check(
272+
assert_type(
273+
pd.concat(
274+
[df, df2, df, df2],
275+
keys=[("foo", "one"), ("foo", "two"), ("baz", "one"), ("baz", "two")],
276+
levels=levels,
277+
names=None,
278+
),
279+
pd.DataFrame,
280+
),
281+
pd.DataFrame,
282+
)
251283

252284
check(
253285
assert_type(

0 commit comments

Comments
 (0)