Skip to content

Commit bef36c1

Browse files
committed
Merge branch 'main' of https://github.com/pandas-dev/pandas into enforce_groupby_apply
2 parents 05a5157 + d41884b commit bef36c1

File tree

8 files changed

+24
-75
lines changed

8 files changed

+24
-75
lines changed

pandas/io/sql.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def read_sql_table( # pyright: ignore[reportOverlappingOverload]
241241
schema=...,
242242
index_col: str | list[str] | None = ...,
243243
coerce_float=...,
244-
parse_dates: list[str] | dict[str, str] | None = ...,
244+
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = ...,
245245
columns: list[str] | None = ...,
246246
chunksize: None = ...,
247247
dtype_backend: DtypeBackend | lib.NoDefault = ...,
@@ -255,7 +255,7 @@ def read_sql_table(
255255
schema=...,
256256
index_col: str | list[str] | None = ...,
257257
coerce_float=...,
258-
parse_dates: list[str] | dict[str, str] | None = ...,
258+
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = ...,
259259
columns: list[str] | None = ...,
260260
chunksize: int = ...,
261261
dtype_backend: DtypeBackend | lib.NoDefault = ...,
@@ -268,7 +268,7 @@ def read_sql_table(
268268
schema: str | None = None,
269269
index_col: str | list[str] | None = None,
270270
coerce_float: bool = True,
271-
parse_dates: list[str] | dict[str, str] | None = None,
271+
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = None,
272272
columns: list[str] | None = None,
273273
chunksize: int | None = None,
274274
dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default,
@@ -372,7 +372,7 @@ def read_sql_query( # pyright: ignore[reportOverlappingOverload]
372372
index_col: str | list[str] | None = ...,
373373
coerce_float=...,
374374
params: list[Any] | Mapping[str, Any] | None = ...,
375-
parse_dates: list[str] | dict[str, str] | None = ...,
375+
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = ...,
376376
chunksize: None = ...,
377377
dtype: DtypeArg | None = ...,
378378
dtype_backend: DtypeBackend | lib.NoDefault = ...,
@@ -386,7 +386,7 @@ def read_sql_query(
386386
index_col: str | list[str] | None = ...,
387387
coerce_float=...,
388388
params: list[Any] | Mapping[str, Any] | None = ...,
389-
parse_dates: list[str] | dict[str, str] | None = ...,
389+
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = ...,
390390
chunksize: int = ...,
391391
dtype: DtypeArg | None = ...,
392392
dtype_backend: DtypeBackend | lib.NoDefault = ...,
@@ -399,7 +399,7 @@ def read_sql_query(
399399
index_col: str | list[str] | None = None,
400400
coerce_float: bool = True,
401401
params: list[Any] | Mapping[str, Any] | None = None,
402-
parse_dates: list[str] | dict[str, str] | None = None,
402+
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = None,
403403
chunksize: int | None = None,
404404
dtype: DtypeArg | None = None,
405405
dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default,

pandas/tests/groupby/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ def get_groupby_method_args(name, obj):
22
"""
33
Get required arguments for a groupby method.
44
5-
When parametrizing a test over groupby methods (e.g. "sum", "mean", "fillna"),
5+
When parametrizing a test over groupby methods (e.g. "sum", "mean"),
66
it is often the case that arguments are required for certain methods.
77
88
Parameters
@@ -16,7 +16,7 @@ def get_groupby_method_args(name, obj):
1616
-------
1717
A tuple of required arguments for the method.
1818
"""
19-
if name in ("nth", "fillna", "take"):
19+
if name in ("nth", "take"):
2020
return (0,)
2121
if name == "quantile":
2222
return (0.5,)

pandas/tests/groupby/test_categorical.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,10 +1955,7 @@ def test_category_order_transformer(
19551955
df = df.set_index(keys)
19561956
args = get_groupby_method_args(transformation_func, df)
19571957
gb = df.groupby(keys, as_index=as_index, sort=sort, observed=observed)
1958-
warn = FutureWarning if transformation_func == "fillna" else None
1959-
msg = "DataFrameGroupBy.fillna is deprecated"
1960-
with tm.assert_produces_warning(warn, match=msg):
1961-
op_result = getattr(gb, transformation_func)(*args)
1958+
op_result = getattr(gb, transformation_func)(*args)
19621959
result = op_result.index.get_level_values("a").categories
19631960
expected = Index([1, 4, 3, 2])
19641961
tm.assert_index_equal(result, expected)

pandas/tests/groupby/test_groupby.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,36 +2078,14 @@ def test_group_on_empty_multiindex(transformation_func, request):
20782078
df["col_3"] = df["col_3"].astype(int)
20792079
df["col_4"] = df["col_4"].astype(int)
20802080
df = df.set_index(["col_1", "col_2"])
2081-
if transformation_func == "fillna":
2082-
args = ("ffill",)
2083-
else:
2084-
args = ()
2085-
warn = FutureWarning if transformation_func == "fillna" else None
2086-
warn_msg = "DataFrameGroupBy.fillna is deprecated"
2087-
with tm.assert_produces_warning(warn, match=warn_msg):
2088-
result = df.iloc[:0].groupby(["col_1"]).transform(transformation_func, *args)
2089-
with tm.assert_produces_warning(warn, match=warn_msg):
2090-
expected = df.groupby(["col_1"]).transform(transformation_func, *args).iloc[:0]
2081+
result = df.iloc[:0].groupby(["col_1"]).transform(transformation_func)
2082+
expected = df.groupby(["col_1"]).transform(transformation_func).iloc[:0]
20912083
if transformation_func in ("diff", "shift"):
20922084
expected = expected.astype(int)
20932085
tm.assert_equal(result, expected)
20942086

2095-
warn_msg = "SeriesGroupBy.fillna is deprecated"
2096-
with tm.assert_produces_warning(warn, match=warn_msg):
2097-
result = (
2098-
df["col_3"]
2099-
.iloc[:0]
2100-
.groupby(["col_1"])
2101-
.transform(transformation_func, *args)
2102-
)
2103-
warn_msg = "SeriesGroupBy.fillna is deprecated"
2104-
with tm.assert_produces_warning(warn, match=warn_msg):
2105-
expected = (
2106-
df["col_3"]
2107-
.groupby(["col_1"])
2108-
.transform(transformation_func, *args)
2109-
.iloc[:0]
2110-
)
2087+
result = df["col_3"].iloc[:0].groupby(["col_1"]).transform(transformation_func)
2088+
expected = df["col_3"].groupby(["col_1"]).transform(transformation_func).iloc[:0]
21112089
if transformation_func in ("diff", "shift"):
21122090
expected = expected.astype(int)
21132091
tm.assert_equal(result, expected)

pandas/tests/groupby/test_groupby_subclass.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ def test_groupby_preserves_subclass(obj, groupby_func):
3636

3737
args = get_groupby_method_args(groupby_func, obj)
3838

39-
warn = FutureWarning if groupby_func == "fillna" else None
40-
msg = f"{type(grouped).__name__}.fillna is deprecated"
41-
with tm.assert_produces_warning(warn, match=msg, raise_on_extra_warnings=False):
39+
warn = FutureWarning if groupby_func == "corrwith" else None
40+
msg = f"{type(grouped).__name__}.corrwith is deprecated"
41+
with tm.assert_produces_warning(warn, match=msg):
4242
result1 = getattr(grouped, groupby_func)(*args)
43-
with tm.assert_produces_warning(warn, match=msg, raise_on_extra_warnings=False):
43+
with tm.assert_produces_warning(warn, match=msg):
4444
result2 = grouped.agg(groupby_func, *args)
4545

4646
# Reduction or transformation kernels should preserve type

pandas/tests/groupby/test_numeric_only.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,11 @@ def test_numeric_only(kernel, has_arg, numeric_only, keys):
278278
kernel in ("first", "last")
279279
or (
280280
# kernels that work on any dtype and don't have numeric_only arg
281-
kernel in ("any", "all", "bfill", "ffill", "fillna", "nth", "nunique")
281+
kernel in ("any", "all", "bfill", "ffill", "nth", "nunique")
282282
and numeric_only is lib.no_default
283283
)
284284
):
285-
warn = FutureWarning if kernel == "fillna" else None
286-
msg = "DataFrameGroupBy.fillna is deprecated"
287-
with tm.assert_produces_warning(warn, match=msg):
288-
result = method(*args, **kwargs)
285+
result = method(*args, **kwargs)
289286
assert "b" in result.columns
290287
elif has_arg:
291288
assert numeric_only is not True

pandas/tests/groupby/test_raises.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ def test_groupby_raises_string(
144144
),
145145
"diff": (TypeError, "unsupported operand type"),
146146
"ffill": (None, ""),
147-
"fillna": (None, ""),
148147
"first": (None, ""),
149148
"idxmax": (None, ""),
150149
"idxmin": (None, ""),
@@ -211,10 +210,7 @@ def test_groupby_raises_string(
211210
elif groupby_func == "corrwith":
212211
msg = "Cannot perform reduction 'mean' with string dtype"
213212

214-
if groupby_func == "fillna":
215-
kind = "Series" if groupby_series else "DataFrame"
216-
warn_msg = f"{kind}GroupBy.fillna is deprecated"
217-
elif groupby_func == "corrwith":
213+
if groupby_func == "corrwith":
218214
warn_msg = "DataFrameGroupBy.corrwith is deprecated"
219215
else:
220216
warn_msg = ""
@@ -301,7 +297,6 @@ def test_groupby_raises_datetime(
301297
"cumsum": (TypeError, "datetime64 type does not support operation 'cumsum'"),
302298
"diff": (None, ""),
303299
"ffill": (None, ""),
304-
"fillna": (None, ""),
305300
"first": (None, ""),
306301
"idxmax": (None, ""),
307302
"idxmin": (None, ""),
@@ -333,10 +328,7 @@ def test_groupby_raises_datetime(
333328
"var": (TypeError, "datetime64 type does not support operation 'var'"),
334329
}[groupby_func]
335330

336-
if groupby_func == "fillna":
337-
kind = "Series" if groupby_series else "DataFrame"
338-
warn_msg = f"{kind}GroupBy.fillna is deprecated"
339-
elif groupby_func == "corrwith":
331+
if groupby_func == "corrwith":
340332
warn_msg = "DataFrameGroupBy.corrwith is deprecated"
341333
else:
342334
warn_msg = ""
@@ -457,7 +449,6 @@ def test_groupby_raises_category(
457449
r"unsupported operand type\(s\) for -: 'Categorical' and 'Categorical'",
458450
),
459451
"ffill": (None, ""),
460-
"fillna": (None, ""), # no-op with CoW
461452
"first": (None, ""),
462453
"idxmax": (None, ""),
463454
"idxmin": (None, ""),
@@ -532,10 +523,7 @@ def test_groupby_raises_category(
532523
),
533524
}[groupby_func]
534525

535-
if groupby_func == "fillna":
536-
kind = "Series" if groupby_series else "DataFrame"
537-
warn_msg = f"{kind}GroupBy.fillna is deprecated"
538-
elif groupby_func == "corrwith":
526+
if groupby_func == "corrwith":
539527
warn_msg = "DataFrameGroupBy.corrwith is deprecated"
540528
else:
541529
warn_msg = ""
@@ -650,7 +638,6 @@ def test_groupby_raises_category_on_category(
650638
),
651639
"diff": (TypeError, "unsupported operand type"),
652640
"ffill": (None, ""),
653-
"fillna": (None, ""), # no-op with CoW
654641
"first": (None, ""),
655642
"idxmax": (ValueError, "empty group due to unobserved categories")
656643
if empty_groups
@@ -710,10 +697,7 @@ def test_groupby_raises_category_on_category(
710697
),
711698
}[groupby_func]
712699

713-
if groupby_func == "fillna":
714-
kind = "Series" if groupby_series else "DataFrame"
715-
warn_msg = f"{kind}GroupBy.fillna is deprecated"
716-
elif groupby_func == "corrwith":
700+
if groupby_func == "corrwith":
717701
warn_msg = "DataFrameGroupBy.corrwith is deprecated"
718702
else:
719703
warn_msg = ""

pandas/tests/groupby/transform/test_transform.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,6 @@ def test_transform_transformation_func(transformation_func):
329329
if transformation_func == "cumcount":
330330
test_op = lambda x: x.transform("cumcount")
331331
mock_op = lambda x: Series(range(len(x)), x.index)
332-
elif transformation_func == "fillna":
333-
test_op = lambda x: x.transform("fillna", value=0)
334-
mock_op = lambda x: x.fillna(value=0)
335332
elif transformation_func == "ngroup":
336333
test_op = lambda x: x.transform("ngroup")
337334
counter = -1
@@ -1430,11 +1427,7 @@ def test_null_group_str_transformer_series(dropna, transformation_func):
14301427
dtype = object if transformation_func in ("any", "all") else None
14311428
buffer.append(Series([np.nan], index=[3], dtype=dtype))
14321429
expected = concat(buffer)
1433-
1434-
warn = FutureWarning if transformation_func == "fillna" else None
1435-
msg = "SeriesGroupBy.fillna is deprecated"
1436-
with tm.assert_produces_warning(warn, match=msg):
1437-
result = gb.transform(transformation_func, *args)
1430+
result = gb.transform(transformation_func, *args)
14381431

14391432
tm.assert_equal(result, expected)
14401433

0 commit comments

Comments
 (0)