From 7dd7b6a037819729da84a94bcda4d2f731e43bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20W=C3=B6rtwein?= <6618166+twoertwein@users.noreply.github.com> Date: Fri, 1 Mar 2024 21:50:47 -0500 Subject: [PATCH] fix concat for axis=0 (#880) * fix concat for axis=0 * 'fix' mypy --- .pre-commit-config.yaml | 4 ++-- pandas-stubs/core/reshape/concat.pyi | 5 ++--- tests/test_pandas.py | 12 ++++++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a0e7af32..7cd5ce04 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ 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 @@ -11,7 +11,7 @@ repos: hooks: - id: isort - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.2.1 + rev: v0.3.0 hooks: - id: ruff args: [ diff --git a/pandas-stubs/core/reshape/concat.pyi b/pandas-stubs/core/reshape/concat.pyi index 54de1be3..7ee1913b 100644 --- a/pandas-stubs/core/reshape/concat.pyi +++ b/pandas-stubs/core/reshape/concat.pyi @@ -16,7 +16,6 @@ from typing_extensions import Never from pandas._typing import ( Axis, - AxisColumn, AxisIndex, HashableT1, HashableT2, @@ -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 = ..., @@ -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] = ..., diff --git a/tests/test_pandas.py b/tests/test_pandas.py index 71551bbd..fddce825 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -62,6 +62,7 @@ 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) @@ -69,6 +70,10 @@ def test_types_concat_none() -> None: 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 @@ -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) @@ -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]})