Skip to content

Commit 4815873

Browse files
GH1246 PR feedback
1 parent 69bbab5 commit 4815873

File tree

4 files changed

+50
-132
lines changed

4 files changed

+50
-132
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repos:
1111
hooks:
1212
- id: isort
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.11.5
14+
rev: v0.11.13
1515
hooks:
1616
- id: ruff
1717
args: [

tests/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
TYPE_CHECKING_INVALID_USAGE: Final = TYPE_CHECKING
5252
WINDOWS = os.name == "nt" or "cygwin" in platform.system().lower()
5353
PD_LTE_23 = Version(pd.__version__) < Version("2.3.999")
54-
PD_LTE_22 = Version(pd.__version__) < Version("2.2.999")
5554
NUMPY20 = np.lib.NumpyVersion(np.__version__) >= "2.0.0"
5655

5756

tests/test_frame.py

Lines changed: 29 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
from pandas._typing import Scalar
4949

5050
from tests import (
51-
PD_LTE_22,
5251
PD_LTE_23,
5352
TYPE_CHECKING_INVALID_USAGE,
5453
check,
@@ -1542,21 +1541,6 @@ def test_types_groupby() -> None:
15421541
assert_type(df.groupby(by=["col1", "col2"]).nunique(), pd.DataFrame),
15431542
pd.DataFrame,
15441543
)
1545-
with pytest_warns_bounded(
1546-
FutureWarning,
1547-
"(The provided callable <built-in function sum> is currently using|The behavior of DataFrame.sum with)",
1548-
upper="2.2.99",
1549-
):
1550-
with pytest_warns_bounded(
1551-
DeprecationWarning,
1552-
"DataFrameGroupBy.apply operated on the grouping columns",
1553-
upper="2.2.99",
1554-
):
1555-
if PD_LTE_22:
1556-
check(
1557-
assert_type(df.groupby(by="col1").apply(sum), pd.DataFrame),
1558-
pd.DataFrame,
1559-
)
15601544
check(assert_type(df.groupby("col1").transform("sum"), pd.DataFrame), pd.DataFrame)
15611545
s1 = df.set_index("col1")["col2"]
15621546
check(assert_type(s1, pd.Series), pd.Series)
@@ -3134,19 +3118,17 @@ def test_frame_stack() -> None:
31343118
def test_frame_reindex() -> None:
31353119
# GH 84
31363120
df = pd.DataFrame({"a": [1, 2, 3]}, index=[0, 1, 2])
3137-
df.reindex([2, 1, 0])
3121+
check(assert_type(df.reindex([2, 1, 0]), pd.DataFrame), pd.DataFrame)
31383122

31393123

31403124
def test_frame_reindex_like() -> None:
31413125
# GH 84
31423126
df = pd.DataFrame({"a": [1, 2, 3]}, index=[0, 1, 2])
31433127
other = pd.DataFrame({"a": [1, 2]}, index=[1, 0])
3144-
31453128
with pytest_warns_bounded(
31463129
FutureWarning,
31473130
"the 'method' keyword is deprecated and will be removed in a future version. Please take steps to stop the use of 'method'",
3148-
lower="2.2.99",
3149-
upper="2.2.99",
3131+
lower="2.3.0",
31503132
):
31513133
check(
31523134
assert_type(
@@ -3449,72 +3431,45 @@ def test_groupby_apply() -> None:
34493431
def sum_mean(x: pd.DataFrame) -> float:
34503432
return x.sum().mean()
34513433

3452-
with (
3453-
pytest_warns_bounded(
3454-
DeprecationWarning,
3455-
"DataFrameGroupBy.apply operated on the grouping columns.",
3456-
upper="2.2.99",
3457-
),
3458-
pytest_warns_bounded(
3459-
FutureWarning,
3460-
"DataFrameGroupBy.apply operated on the grouping columns.",
3461-
lower="2.2.99",
3462-
upper="2.3.99",
3463-
),
3434+
with pytest_warns_bounded(
3435+
FutureWarning,
3436+
"DataFrameGroupBy.apply operated on the grouping columns.",
3437+
lower="2.2.99",
3438+
upper="2.3.99",
34643439
):
34653440
check(
34663441
assert_type(df.groupby("col1").apply(sum_mean), pd.Series),
34673442
pd.Series,
34683443
)
34693444

34703445
lfunc: Callable[[pd.DataFrame], float] = lambda x: x.sum().mean()
3471-
with (
3472-
pytest_warns_bounded(
3473-
DeprecationWarning,
3474-
"DataFrameGroupBy.apply operated on the grouping columns.",
3475-
upper="2.2.99",
3476-
),
3477-
pytest_warns_bounded(
3478-
FutureWarning,
3479-
"DataFrameGroupBy.apply operated on the grouping columns.",
3480-
lower="2.2.99",
3481-
),
3446+
with pytest_warns_bounded(
3447+
FutureWarning,
3448+
"DataFrameGroupBy.apply operated on the grouping columns.",
3449+
lower="2.2.99",
3450+
upper="2.99.99",
34823451
):
34833452
check(assert_type(df.groupby("col1").apply(lfunc), pd.Series), pd.Series)
34843453

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

3488-
with (
3489-
pytest_warns_bounded(
3490-
DeprecationWarning,
3491-
"DataFrameGroupBy.apply operated on the grouping columns.",
3492-
upper="2.2.99",
3493-
),
3494-
pytest_warns_bounded(
3495-
FutureWarning,
3496-
"DataFrameGroupBy.apply operated on the grouping columns.",
3497-
lower="2.2.99",
3498-
upper="2.3.99",
3499-
),
3457+
with pytest_warns_bounded(
3458+
FutureWarning,
3459+
"DataFrameGroupBy.apply operated on the grouping columns.",
3460+
lower="2.2.99",
3461+
upper="2.3.99",
35003462
):
35013463
check(assert_type(df.groupby("col1").apply(sum_to_list), pd.Series), pd.Series)
35023464

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

3506-
with (
3507-
pytest_warns_bounded(
3508-
DeprecationWarning,
3509-
"DataFrameGroupBy.apply operated on the grouping columns.",
3510-
upper="2.2.99",
3511-
),
3512-
pytest_warns_bounded(
3513-
FutureWarning,
3514-
"DataFrameGroupBy.apply operated on the grouping columns.",
3515-
lower="2.2.99",
3516-
upper="2.3.99",
3517-
),
3468+
with pytest_warns_bounded(
3469+
FutureWarning,
3470+
"DataFrameGroupBy.apply operated on the grouping columns.",
3471+
lower="2.2.99",
3472+
upper="2.3.99",
35183473
):
35193474
check(
35203475
assert_type(df.groupby("col1").apply(sum_to_series), pd.DataFrame),
@@ -3524,18 +3479,11 @@ def sum_to_series(x: pd.DataFrame) -> pd.Series:
35243479
def sample_to_df(x: pd.DataFrame) -> pd.DataFrame:
35253480
return x.sample()
35263481

3527-
with (
3528-
pytest_warns_bounded(
3529-
DeprecationWarning,
3530-
"DataFrameGroupBy.apply operated on the grouping columns.",
3531-
upper="2.2.99",
3532-
),
3533-
pytest_warns_bounded(
3534-
FutureWarning,
3535-
"DataFrameGroupBy.apply operated on the grouping columns.",
3536-
lower="2.2.99",
3537-
upper="2.3.99",
3538-
),
3482+
with pytest_warns_bounded(
3483+
FutureWarning,
3484+
"DataFrameGroupBy.apply operated on the grouping columns.",
3485+
lower="2.2.99",
3486+
upper="2.3.99",
35393487
):
35403488
check(
35413489
assert_type(
@@ -4424,13 +4372,12 @@ def test_transpose() -> None:
44244372
df = pd.DataFrame({"a": [1, 1, 2], "b": [4, 5, 6]})
44254373
check(assert_type(df.transpose(), pd.DataFrame), pd.DataFrame)
44264374
check(assert_type(df.transpose(None), pd.DataFrame), pd.DataFrame)
4427-
44284375
msg = "The copy keyword is deprecated and will be removed in a future"
44294376
with pytest_warns_bounded(
44304377
DeprecationWarning,
44314378
msg,
4432-
lower="2.2.99",
4433-
upper="2.2.99",
4379+
lower="2.3.99",
4380+
upper="3.0.0",
44344381
):
44354382
check(assert_type(df.transpose(copy=True), pd.DataFrame), pd.DataFrame)
44364383

tests/test_groupby.py

Lines changed: 20 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,11 @@ def test_frame_groupby_resample() -> None:
7777
check(assert_type(GB_DF.resample("ME").ax, Index), DatetimeIndex)
7878

7979
# agg funcs
80-
with (
81-
pytest_warns_bounded(
82-
DeprecationWarning,
83-
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
84-
upper="2.2.99",
85-
),
86-
pytest_warns_bounded(
87-
FutureWarning,
88-
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
89-
lower="2.2.99",
90-
upper="2.3.99",
91-
),
80+
with pytest_warns_bounded(
81+
FutureWarning,
82+
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
83+
lower="2.2.99",
84+
upper="2.3.99",
9285
):
9386
check(assert_type(GB_DF.resample("ME").sum(), DataFrame), DataFrame)
9487
check(assert_type(GB_DF.resample("ME").prod(), DataFrame), DataFrame)
@@ -132,18 +125,11 @@ def test_frame_groupby_resample() -> None:
132125
GB_DF.resample("ME").fillna("ffill") # type: ignore[operator] # pyright: ignore
133126

134127
# aggregate / apply
135-
with (
136-
pytest_warns_bounded(
137-
DeprecationWarning,
138-
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
139-
upper="2.2.99",
140-
),
141-
pytest_warns_bounded(
142-
FutureWarning,
143-
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
144-
lower="2.2.99",
145-
upper="2.3.99",
146-
),
128+
with pytest_warns_bounded(
129+
FutureWarning,
130+
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
131+
lower="2.2.99",
132+
upper="2.3.99",
147133
):
148134
with pytest_warns_bounded(
149135
FutureWarning,
@@ -188,18 +174,11 @@ def test_frame_groupby_resample() -> None:
188174
def f(val: DataFrame) -> Series:
189175
return val.mean()
190176

191-
with (
192-
pytest_warns_bounded(
193-
DeprecationWarning,
194-
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
195-
upper="2.2.99",
196-
),
197-
pytest_warns_bounded(
198-
FutureWarning,
199-
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
200-
lower="2.2.99",
201-
upper="2.3.99",
202-
),
177+
with pytest_warns_bounded(
178+
FutureWarning,
179+
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
180+
lower="2.2.99",
181+
upper="2.3.99",
203182
):
204183
check(assert_type(GB_DF.resample("ME").aggregate(f), DataFrame), DataFrame)
205184

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

216-
with (
217-
pytest_warns_bounded(
218-
DeprecationWarning,
219-
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
220-
upper="2.2.99",
221-
),
222-
pytest_warns_bounded(
223-
FutureWarning,
224-
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
225-
lower="2.2.99",
226-
upper="2.3.99",
227-
),
195+
with pytest_warns_bounded(
196+
FutureWarning,
197+
"DataFrameGroupBy.(apply|resample) operated on the grouping columns",
198+
lower="2.2.99",
199+
upper="2.3.99",
228200
):
229201
with pytest_warns_bounded(
230202
FutureWarning,

0 commit comments

Comments
 (0)