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 .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
1 change: 0 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
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")
NUMPY20 = np.lib.NumpyVersion(np.__version__) >= "2.0.0"


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

from tests import (
PD_LTE_22,
PD_LTE_23,
TYPE_CHECKING_INVALID_USAGE,
check,
Expand Down Expand Up @@ -1542,21 +1541,6 @@ def test_types_groupby() -> None:
assert_type(df.groupby(by=["col1", "col2"]).nunique(), pd.DataFrame),
pd.DataFrame,
)
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",
):
with pytest_warns_bounded(
DeprecationWarning,
"DataFrameGroupBy.apply operated on the grouping columns",
upper="2.2.99",
):
if PD_LTE_22:
check(
assert_type(df.groupby(by="col1").apply(sum), pd.DataFrame),
pd.DataFrame,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test needs to remain, but use 2 FutureWarning with upper="2.3.99" and have a check on PD_LTE_23

check(assert_type(df.groupby("col1").transform("sum"), pd.DataFrame), pd.DataFrame)
s1 = df.set_index("col1")["col2"]
check(assert_type(s1, pd.Series), pd.Series)
Expand Down Expand Up @@ -3134,19 +3118,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="2.2.99",
lower="2.3.0",
):
check(
assert_type(
Expand Down Expand Up @@ -3449,72 +3431,45 @@ 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.2.99",
),
pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
lower="2.2.99",
upper="2.3.99",
),
with 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.

keep this at upper="2.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.2.99",
),
pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
lower="2.2.99",
),
with pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
lower="2.2.99",
upper="2.99.99",
Copy link
Collaborator

Choose a reason for hiding this comment

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

keep this at upper="2.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.2.99",
),
pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
lower="2.2.99",
upper="2.3.99",
),
with 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.

keep this at upper="2.99"

):
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.2.99",
),
pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
lower="2.2.99",
upper="2.3.99",
),
with 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.

keep this at upper="2.99"

):
check(
assert_type(df.groupby("col1").apply(sum_to_series), pd.DataFrame),
Expand All @@ -3524,18 +3479,11 @@ 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.2.99",
),
pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.apply operated on the grouping columns.",
lower="2.2.99",
upper="2.3.99",
),
with 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.

keep this at upper="2.99"

):
check(
assert_type(
Expand Down Expand Up @@ -4424,13 +4372,12 @@ 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",
upper="2.2.99",
lower="2.3.99",
upper="3.0.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove the upper here.

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

Expand Down
68 changes: 20 additions & 48 deletions tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,11 @@ def test_frame_groupby_resample() -> None:
check(assert_type(GB_DF.resample("ME").ax, Index), DatetimeIndex)

# agg funcs
with (
pytest_warns_bounded(
DeprecationWarning,
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
upper="2.2.99",
),
pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
lower="2.2.99",
upper="2.3.99",
),
with pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.(apply|resample) 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.

keep this at upper="2.99"

):
check(assert_type(GB_DF.resample("ME").sum(), DataFrame), DataFrame)
check(assert_type(GB_DF.resample("ME").prod(), DataFrame), DataFrame)
Expand Down Expand Up @@ -132,18 +125,11 @@ def test_frame_groupby_resample() -> None:
GB_DF.resample("ME").fillna("ffill") # type: ignore[operator] # pyright: ignore

# aggregate / apply
with (
pytest_warns_bounded(
DeprecationWarning,
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
upper="2.2.99",
),
pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
lower="2.2.99",
upper="2.3.99",
),
with pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.(apply|resample) 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.

keep this at upper="2.99"

):
with pytest_warns_bounded(
FutureWarning,
Expand Down Expand Up @@ -188,18 +174,11 @@ def test_frame_groupby_resample() -> None:
def f(val: DataFrame) -> Series:
return val.mean()

with (
pytest_warns_bounded(
DeprecationWarning,
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
upper="2.2.99",
),
pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
lower="2.2.99",
upper="2.3.99",
),
with pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.(apply|resample) 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.

keep this at upper="2.99"

):
check(assert_type(GB_DF.resample("ME").aggregate(f), DataFrame), DataFrame)

Expand All @@ -213,18 +192,11 @@ def df2series(val: DataFrame) -> Series:
def df2scalar(val: DataFrame) -> float:
return float(val.mean().mean())

with (
pytest_warns_bounded(
DeprecationWarning,
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
upper="2.2.99",
),
pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
lower="2.2.99",
upper="2.3.99",
),
with pytest_warns_bounded(
FutureWarning,
"DataFrameGroupBy.(apply|resample) 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.

keep this at upper="2.99"

):
with pytest_warns_bounded(
FutureWarning,
Expand Down