Skip to content

GH1246 Upgrade to pandas 2.3.0 #1247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.5
rev: v0.11.13
hooks:
- id: ruff
args: [
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ty = "^0.0.1a8"

[tool.poetry.group.dev.dependencies]
mypy = "1.16.0"
pandas = "2.2.3"
pandas = "2.3.0"
pyarrow = ">=10.0.1"
pytest = ">=7.1.2"
pyright = ">=1.1.400"
Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

TYPE_CHECKING_INVALID_USAGE: Final = TYPE_CHECKING
WINDOWS = os.name == "nt" or "cygwin" in platform.system().lower()
PD_LTE_22 = Version(pd.__version__) < Version("2.2.999")
PD_LTE_23 = Version(pd.__version__) < Version("2.3.999")
NUMPY20 = np.lib.NumpyVersion(np.__version__) >= "2.0.0"


Expand Down
6 changes: 3 additions & 3 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from tests import (
PD_LTE_22,
PD_LTE_23,
WINDOWS,
)

Expand Down Expand Up @@ -108,13 +108,13 @@ def test_specification_error() -> None:


def test_setting_with_copy_error() -> None:
if PD_LTE_22:
if PD_LTE_23:
with pytest.raises(errors.SettingWithCopyError):
raise errors.SettingWithCopyError()


def test_setting_with_copy_warning() -> None:
if PD_LTE_22:
if PD_LTE_23:
with pytest.warns(errors.SettingWithCopyWarning):
warnings.warn("", errors.SettingWithCopyWarning)

Expand Down
66 changes: 34 additions & 32 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from pandas._typing import Scalar

from tests import (
PD_LTE_22,
PD_LTE_23,
TYPE_CHECKING_INVALID_USAGE,
check,
ensure_clean,
Expand Down Expand Up @@ -450,7 +450,7 @@ def test_types_drop_duplicates() -> None:
pd.DataFrame,
)

if not PD_LTE_22:
if not PD_LTE_23:
check(assert_type(df.drop_duplicates({"AAA"}), pd.DataFrame), pd.DataFrame)
check(
assert_type(df.drop_duplicates({"AAA": None}), pd.DataFrame), pd.DataFrame
Expand Down Expand Up @@ -1544,14 +1544,14 @@ def test_types_groupby() -> None:
with pytest_warns_bounded(
FutureWarning,
"(The provided callable <built-in function sum> is currently using|The behavior of DataFrame.sum with)",
upper="2.2.99",
upper="2.3.99",
):
with pytest_warns_bounded(
DeprecationWarning,
FutureWarning,
"DataFrameGroupBy.apply operated on the grouping columns",
upper="2.2.99",
upper="2.3.99",
):
if PD_LTE_22:
if PD_LTE_23:
check(
assert_type(df.groupby(by="col1").apply(sum), pd.DataFrame),
pd.DataFrame,
Expand Down Expand Up @@ -1602,7 +1602,7 @@ def wrapped_min(x: Any) -> Any:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <built-in function (min|max)> is currently using",
upper="2.2.99",
upper="2.3.99",
):
check(assert_type(df.groupby("col1")["col3"].agg(min), pd.Series), pd.Series)
check(
Expand Down Expand Up @@ -1751,7 +1751,7 @@ def test_types_window() -> None:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <built-in function (min|max)> is currently using",
upper="2.2.99",
upper="2.3.99",
):
check(
assert_type(df.rolling(2).agg(max), pd.DataFrame),
Expand Down Expand Up @@ -1860,7 +1860,7 @@ def test_types_agg() -> None:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <(built-in function (min|max|mean)|function mean at 0x\w+)> is currently using",
upper="2.2.99",
upper="2.3.99",
):
check(assert_type(df.agg(min), pd.Series), pd.Series)
check(assert_type(df.agg([min, max]), pd.DataFrame), pd.DataFrame)
Expand All @@ -1887,7 +1887,7 @@ def test_types_aggregate() -> None:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <built-in function (min|max)> is currently using",
upper="2.2.99",
upper="2.3.99",
):
check(assert_type(df.aggregate(min), pd.Series), pd.Series)
check(assert_type(df.aggregate([min, max]), pd.DataFrame), pd.DataFrame)
Expand Down Expand Up @@ -2020,7 +2020,7 @@ def test_types_resample() -> None:
FutureWarning,
"'M' is deprecated",
lower="2.1.99",
upper="2.2.99",
upper="2.3.99",
upper_exception=ValueError,
):
df.resample("M", on="date")
Expand Down Expand Up @@ -2163,7 +2163,7 @@ def resampler_foo(resampler: Resampler[pd.DataFrame]) -> pd.DataFrame:
FutureWarning,
"'M' is deprecated",
lower="2.1.99",
upper="2.2.99",
upper="2.3.99",
upper_exception=ValueError,
):
(
Expand Down Expand Up @@ -2504,7 +2504,7 @@ def test_types_regressions() -> None:
tslist = list(pd.to_datetime(["2022-01-01", "2022-01-02"]))
check(assert_type(tslist, list[pd.Timestamp]), list, pd.Timestamp)
sseries = pd.Series(tslist)
with pytest_warns_bounded(FutureWarning, "'d' is deprecated", lower="2.2.99"):
with pytest_warns_bounded(FutureWarning, "'d' is deprecated", lower="2.3.99"):
sseries + pd.Timedelta(1, "d")

check(
Expand All @@ -2518,7 +2518,7 @@ def test_types_regressions() -> None:
FutureWarning,
"'H' is deprecated",
lower="2.1.99",
upper="2.2.99",
upper="2.3.99",
upper_exception=ValueError,
):
pd.date_range(start="2021-12-01", periods=24, freq="H")
Expand Down Expand Up @@ -2644,7 +2644,7 @@ class ReadCsvKwargs(TypedDict):
),
pd.DataFrame,
)
if PD_LTE_22:
if PD_LTE_23:
parse_dates_2 = {"combined_date": ["Year", "Month", "Day"]}
with pytest_warns_bounded(
FutureWarning,
Expand Down Expand Up @@ -3098,7 +3098,7 @@ def test_frame_stack() -> None:
with pytest_warns_bounded(
FutureWarning,
"The previous implementation of stack is deprecated",
upper="2.2.99",
upper="2.3.99",
):
check(
assert_type(
Expand All @@ -3113,7 +3113,7 @@ def test_frame_stack() -> None:
),
pd.Series,
)
if PD_LTE_22:
if PD_LTE_23:
check(
assert_type(
df_multi_level_cols2.stack(0, future_stack=False),
Expand All @@ -3133,19 +3133,17 @@ def test_frame_stack() -> None:
def test_frame_reindex() -> None:
# GH 84
df = pd.DataFrame({"a": [1, 2, 3]}, index=[0, 1, 2])
df.reindex([2, 1, 0])
check(assert_type(df.reindex([2, 1, 0]), pd.DataFrame), pd.DataFrame)


def test_frame_reindex_like() -> None:
# GH 84
df = pd.DataFrame({"a": [1, 2, 3]}, index=[0, 1, 2])
other = pd.DataFrame({"a": [1, 2]}, index=[1, 0])

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.2.99",
upper="3.0.99",
lower="2.3.0",
):
check(
assert_type(
Expand Down Expand Up @@ -3277,7 +3275,7 @@ def test_groupby_result() -> None:
index, value = next(iterator)
assert_type((index, value), tuple[tuple, pd.DataFrame])

if PD_LTE_22:
if PD_LTE_23:
check(assert_type(index, tuple), tuple, np.integer)
else:
check(assert_type(index, tuple), tuple, int)
Expand Down Expand Up @@ -3389,7 +3387,7 @@ def test_groupby_result_for_ambiguous_indexes() -> None:
with pytest_warns_bounded(
FutureWarning,
"The default of observed=False is deprecated",
upper="2.2.99",
upper="2.3.99",
):
categorical_index = pd.CategoricalIndex(df.a)
iterator2 = df.groupby(categorical_index).__iter__()
Expand Down Expand Up @@ -3449,8 +3447,9 @@ def sum_mean(x: pd.DataFrame) -> float:
return x.sum().mean()

with pytest_warns_bounded(
DeprecationWarning,
FutureWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
lower="2.2.99",
upper="2.99",
):
check(
Expand All @@ -3460,8 +3459,9 @@ def sum_mean(x: pd.DataFrame) -> float:

lfunc: Callable[[pd.DataFrame], float] = lambda x: x.sum().mean()
with pytest_warns_bounded(
DeprecationWarning,
FutureWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
lower="2.2.99",
upper="2.99",
):
check(assert_type(df.groupby("col1").apply(lfunc), pd.Series), pd.Series)
Expand All @@ -3470,8 +3470,9 @@ def sum_to_list(x: pd.DataFrame) -> list:
return x.sum().tolist()

with pytest_warns_bounded(
DeprecationWarning,
FutureWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
lower="2.2.99",
upper="2.99",
):
check(assert_type(df.groupby("col1").apply(sum_to_list), pd.Series), pd.Series)
Expand All @@ -3480,8 +3481,9 @@ def sum_to_series(x: pd.DataFrame) -> pd.Series:
return x.sum()

with pytest_warns_bounded(
DeprecationWarning,
FutureWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
lower="2.2.99",
upper="2.99",
):
check(
Expand All @@ -3493,8 +3495,9 @@ def sample_to_df(x: pd.DataFrame) -> pd.DataFrame:
return x.sample()

with pytest_warns_bounded(
DeprecationWarning,
FutureWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
lower="2.2.99",
upper="2.99",
):
check(
Expand Down Expand Up @@ -3769,7 +3772,7 @@ def test_resample_150_changes() -> None:
FutureWarning,
"'M' is deprecated",
lower="2.1.99",
upper="2.2.99",
upper="2.99",
upper_exception=ValueError,
):
frame.resample("M", group_keys=True)
Expand Down Expand Up @@ -3872,7 +3875,7 @@ def test_getattr_and_dataframe_groupby() -> None:
with pytest_warns_bounded(
FutureWarning,
r"The provided callable <built-in function (min|max)> is currently using",
upper="2.2.99",
upper="2.3.99",
):
check(assert_type(df.groupby("col1").col3.agg(min), pd.Series), pd.Series)
check(
Expand Down Expand Up @@ -4384,12 +4387,11 @@ def test_transpose() -> None:
df = pd.DataFrame({"a": [1, 1, 2], "b": [4, 5, 6]})
check(assert_type(df.transpose(), pd.DataFrame), pd.DataFrame)
check(assert_type(df.transpose(None), pd.DataFrame), pd.DataFrame)

msg = "The copy keyword is deprecated and will be removed in a future"
with pytest_warns_bounded(
DeprecationWarning,
msg,
lower="2.2.99",
lower="2.3.99",
):
check(assert_type(df.transpose(copy=True), pd.DataFrame), pd.DataFrame)

Expand Down
Loading