diff --git a/pyproject.toml b/pyproject.toml index 71400163a..a60a4f6ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,7 @@ numpy = ">= 1.23.5" [tool.poetry.group.dev.dependencies] mypy = "1.17.0" -pandas = "2.3.0" +pandas = "2.3.1" pyarrow = ">=10.0.1" pytest = ">=7.1.2" pyright = ">=1.1.400" diff --git a/tests/test_frame.py b/tests/test_frame.py index ffd85d609..2973d25cb 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -2949,7 +2949,10 @@ def test_dataframe_replace() -> None: check(assert_type(df.replace(regex=pattern, value="x"), pd.DataFrame), pd.DataFrame) check(assert_type(df.replace(["a"], ["x"]), pd.DataFrame), pd.DataFrame) - check(assert_type(df.replace([pattern], ["x"]), pd.DataFrame), pd.DataFrame) + check( + assert_type(df.replace([pattern], ["x"], regex=True), pd.DataFrame), + pd.DataFrame, + ) check(assert_type(df.replace(regex=["a"], value=["x"]), pd.DataFrame), pd.DataFrame) check( assert_type(df.replace(regex=[pattern], value=["x"]), pd.DataFrame), @@ -2958,7 +2961,9 @@ def test_dataframe_replace() -> None: check(assert_type(df.replace({"a": "x"}), pd.DataFrame), pd.DataFrame) check(assert_type(df.replace(replace_dict_scalar), pd.DataFrame), pd.DataFrame) - check(assert_type(df.replace({pattern: "x"}), pd.DataFrame), pd.DataFrame) + check( + assert_type(df.replace({pattern: "x"}, regex=True), pd.DataFrame), pd.DataFrame + ) check(assert_type(df.replace(pd.Series({"a": "x"})), pd.DataFrame), pd.DataFrame) check(assert_type(df.replace(regex={"a": "x"}), pd.DataFrame), pd.DataFrame) check(assert_type(df.replace(regex={pattern: "x"}), pd.DataFrame), pd.DataFrame) @@ -3003,7 +3008,9 @@ def test_dataframe_replace() -> None: pd.DataFrame, ) check( - assert_type(df.replace({"col1": [pattern]}, {"col1": ["x"]}), pd.DataFrame), + assert_type( + df.replace({"col1": [pattern]}, {"col1": ["x"]}, regex=True), pd.DataFrame + ), pd.DataFrame, ) check( @@ -3037,7 +3044,10 @@ def test_dataframe_replace() -> None: check(assert_type(df.replace({"col1": {"a": "x"}}), pd.DataFrame), pd.DataFrame) check(assert_type(df.replace(replace_dict_per_column), pd.DataFrame), pd.DataFrame) - check(assert_type(df.replace({"col1": {pattern: "x"}}), pd.DataFrame), pd.DataFrame) + check( + assert_type(df.replace({"col1": {pattern: "x"}}, regex=True), pd.DataFrame), + pd.DataFrame, + ) check( assert_type(df.replace({"col1": pd.Series({"a": "x"})}), pd.DataFrame), pd.DataFrame, @@ -3168,7 +3178,7 @@ def test_frame_reindex_like() -> None: with pytest_warns_bounded( FutureWarning, "the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'", - lower="2.3.0", + lower="2.3.99", ): check( assert_type( diff --git a/tests/test_series.py b/tests/test_series.py index 1e48aae75..f58d651f4 100644 --- a/tests/test_series.py +++ b/tests/test_series.py @@ -1428,9 +1428,14 @@ def test_types_values() -> None: assert_type(pd.Series([1, 2, 3]).values, Union[ExtensionArray, np.ndarray]), np.ndarray, ) + valresult_type: type[np.ndarray | ExtensionArray] + if PD_LTE_23: + valresult_type = np.ndarray + else: + valresult_type = ExtensionArray check( assert_type(pd.Series(list("aabc")).values, Union[np.ndarray, ExtensionArray]), - np.ndarray, + valresult_type, ) check( assert_type( @@ -1707,11 +1712,14 @@ def test_series_replace() -> None: pd.Series, ) check( - assert_type(s.replace({pattern: "z"}), "pd.Series[str]"), + assert_type(s.replace({pattern: "z"}, regex=True), "pd.Series[str]"), pd.Series, ) check(assert_type(s.replace(["a"], ["x"]), "pd.Series[str]"), pd.Series) - check(assert_type(s.replace([pattern], ["x"]), "pd.Series[str]"), pd.Series) + check( + assert_type(s.replace([pattern], ["x"], regex=True), "pd.Series[str]"), + pd.Series, + ) check(assert_type(s.replace(r"^a.*", "x", regex=True), "pd.Series[str]"), pd.Series) check(assert_type(s.replace(value="x", regex=r"^a.*"), "pd.Series[str]"), pd.Series) check( @@ -3793,7 +3801,9 @@ def test_path_div() -> None: # GH 682 folder = Path.cwd() files = pd.Series(["a.png", "b.png"]) - check(assert_type(folder / files, pd.Series), pd.Series, Path) + if PD_LTE_23: + # Bug in 3.0 https://github.com/pandas-dev/pandas/issues/61940 + check(assert_type(folder / files, pd.Series), pd.Series, Path) folders = pd.Series([folder, folder]) check(assert_type(folders / Path("a.png"), pd.Series), pd.Series, Path) diff --git a/tests/test_string_accessors.py b/tests/test_string_accessors.py index 649dae780..4a8a0604c 100644 --- a/tests/test_string_accessors.py +++ b/tests/test_string_accessors.py @@ -6,6 +6,7 @@ from typing_extensions import assert_type from tests import ( + PD_LTE_23, check, np_ndarray_bool, ) @@ -38,9 +39,13 @@ def test_string_accessors_boolean_series(): _check( assert_type(s.str.contains("a"), "pd.Series[bool]"), ) - _check( - assert_type(s.str.contains(re.compile(r"a")), "pd.Series[bool]"), - ) + if PD_LTE_23: + # Bug in pandas 3.0 dev https://github.com/pandas-dev/pandas/issues/61942 + _check( + assert_type( + s.str.contains(re.compile(r"a"), regex=True), "pd.Series[bool]" + ), + ) _check(assert_type(s.str.endswith("e"), "pd.Series[bool]")) _check(assert_type(s.str.endswith(("e", "f")), "pd.Series[bool]")) _check(assert_type(s.str.fullmatch("apple"), "pd.Series[bool]")) @@ -66,9 +71,13 @@ def test_string_accessors_boolean_index(): _check( assert_type(idx.str.contains("a"), np_ndarray_bool), ) - _check( - assert_type(idx.str.contains(re.compile(r"a")), np_ndarray_bool), - ) + if PD_LTE_23: + # Bug in pandas 3.0 dev https://github.com/pandas-dev/pandas/issues/61942 + _check( + assert_type( + idx.str.contains(re.compile(r"a"), regex=True), np_ndarray_bool + ), + ) _check(assert_type(idx.str.endswith("e"), np_ndarray_bool)) _check(assert_type(idx.str.endswith(("e", "f")), np_ndarray_bool)) _check(assert_type(idx.str.fullmatch("apple"), np_ndarray_bool))