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 1 commit
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 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
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

TYPE_CHECKING_INVALID_USAGE: Final = TYPE_CHECKING
WINDOWS = os.name == "nt" or "cygwin" in platform.system().lower()
PD_LTE_23 = Version(pd.__version__) < Version("2.3.999")
PD_LTE_22 = Version(pd.__version__) < Version("2.2.999")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should remove the PD_LTE_22

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed!

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
115 changes: 78 additions & 37 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

from tests import (
PD_LTE_22,
PD_LTE_23,
TYPE_CHECKING_INVALID_USAGE,
check,
ensure_clean,
Expand Down Expand Up @@ -450,7 +451,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 @@ -1602,7 +1603,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 +1752,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 +1861,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 +1888,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 +2021,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 +2164,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 +2505,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 +2519,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 +2645,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 +3099,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 +3114,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 Down Expand Up @@ -3145,7 +3146,7 @@ def test_frame_reindex_like() -> None:
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",
upper="2.2.99",
):
check(
assert_type(
Expand Down Expand Up @@ -3277,7 +3278,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 +3390,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 @@ -3448,41 +3449,72 @@ def test_groupby_apply() -> None:
def sum_mean(x: pd.DataFrame) -> float:
return x.sum().mean()

with pytest_warns_bounded(
DeprecationWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
upper="2.99",
with (
pytest_warns_bounded(
DeprecationWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
upper="2.2.99",
),
pytest_warns_bounded(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite annoying that they changed the type of warning that was raised but guess we don't have too much choice than doubling the context manager to grab the warnings.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are testing with 2.3, so you only need to test for FutureWarning with upper="2.3.99"

FutureWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
lower="2.2.99",
upper="2.3.99",
),
):
check(
assert_type(df.groupby("col1").apply(sum_mean), pd.Series),
pd.Series,
)

lfunc: Callable[[pd.DataFrame], float] = lambda x: x.sum().mean()
with pytest_warns_bounded(
DeprecationWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
upper="2.99",
with (
pytest_warns_bounded(
DeprecationWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
upper="2.2.99",
),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this

pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
lower="2.2.99",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to 2.3.99

),
):
check(assert_type(df.groupby("col1").apply(lfunc), pd.Series), pd.Series)

def sum_to_list(x: pd.DataFrame) -> list:
return x.sum().tolist()

with pytest_warns_bounded(
DeprecationWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
upper="2.99",
with (
pytest_warns_bounded(
DeprecationWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
upper="2.2.99",
),
pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
lower="2.2.99",
upper="2.3.99",
),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment - just leave in the 2.3 test since that is all we are testing against

):
check(assert_type(df.groupby("col1").apply(sum_to_list), pd.Series), pd.Series)

def sum_to_series(x: pd.DataFrame) -> pd.Series:
return x.sum()

with pytest_warns_bounded(
DeprecationWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
upper="2.99",
with (
pytest_warns_bounded(
DeprecationWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
upper="2.2.99",
),
pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
lower="2.2.99",
upper="2.3.99",
),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

):
check(
assert_type(df.groupby("col1").apply(sum_to_series), pd.DataFrame),
Expand All @@ -3492,10 +3524,18 @@ def sum_to_series(x: pd.DataFrame) -> pd.Series:
def sample_to_df(x: pd.DataFrame) -> pd.DataFrame:
return x.sample()

with pytest_warns_bounded(
DeprecationWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
upper="2.99",
with (
pytest_warns_bounded(
DeprecationWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
upper="2.2.99",
),
pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
lower="2.2.99",
upper="2.3.99",
),
):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

check(
assert_type(
Expand Down Expand Up @@ -3769,7 +3809,7 @@ def test_resample_150_changes() -> None:
FutureWarning,
"'M' is deprecated",
lower="2.1.99",
upper="2.2.99",
upper="2.3.99",
upper_exception=ValueError,
):
frame.resample("M", group_keys=True)
Expand Down Expand Up @@ -3872,7 +3912,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 @@ -4390,6 +4430,7 @@ def test_transpose() -> None:
DeprecationWarning,
msg,
lower="2.2.99",
upper="2.2.99",
):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since no warning is issued with 2.3, we can just leave out the context manager

check(assert_type(df.transpose(copy=True), pd.DataFrame), pd.DataFrame)

Expand Down
Loading