Skip to content

Commit cece8c6

Browse files
authored
DEPR: Remove sql.execute, *args/**kwargs in resample, unrecognized timezones (#57241)
1 parent 6725e37 commit cece8c6

File tree

7 files changed

+18
-206
lines changed

7 files changed

+18
-206
lines changed

doc/source/whatsnew/v3.0.0.rst

+3
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,11 @@ Removal of prior version deprecations/changes
107107
- Removed ``DataFrameGroupBy.grouper`` and ``SeriesGroupBy.grouper`` (:issue:`56521`)
108108
- Removed ``axis`` argument from :meth:`DataFrame.groupby`, :meth:`Series.groupby`, :meth:`DataFrame.rolling`, :meth:`Series.rolling`, :meth:`DataFrame.resample`, and :meth:`Series.resample` (:issue:`51203`)
109109
- Removed ``axis`` argument from all groupby operations (:issue:`50405`)
110+
- Removed ``pandas.io.sql.execute`` (:issue:`50185`)
110111
- Removed deprecated argument ``obj`` in :meth:`.DataFrameGroupBy.get_group` and :meth:`.SeriesGroupBy.get_group` (:issue:`53545`)
111112
- Removed the ``ArrayManager`` (:issue:`55043`)
113+
- Removed unused arguments ``*args`` and ``**kwargs`` in :class:`Resampler` methods (:issue:`50977`)
114+
- Unrecognized timezones when parsing strings to datetimes now raises a ``ValueError`` (:issue:`51477`)
112115

113116
.. ---------------------------------------------------------------------------
114117
.. _whatsnew_300.performance:

pandas/_libs/tslibs/parsing.pyx

+3-8
Original file line numberDiff line numberDiff line change
@@ -733,15 +733,10 @@ cdef datetime dateutil_parse(
733733
)
734734
elif res.tzname is not None:
735735
# e.g. "1994 Jan 15 05:16 FOO" where FOO is not recognized
736-
# GH#18702
737-
warnings.warn(
736+
# GH#18702, # GH 50235 enforced in 3.0
737+
raise ValueError(
738738
f'Parsed string "{timestr}" included an un-recognized timezone '
739-
f'"{res.tzname}". Dropping unrecognized timezones is deprecated; '
740-
"in a future version this will raise. Instead pass the string "
741-
"without the timezone, then use .tz_localize to convert to a "
742-
"recognized timezone.",
743-
FutureWarning,
744-
stacklevel=find_stack_level()
739+
f'"{res.tzname}".'
745740
)
746741

747742
out_bestunit[0] = attrname_to_npy_unit[reso]

pandas/core/resample.py

+3-94
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
)
2828
from pandas._libs.tslibs.dtypes import freq_to_period_freqstr
2929
from pandas._typing import NDFrameT
30-
from pandas.compat.numpy import function as nv
3130
from pandas.errors import AbstractMethodError
3231
from pandas.util._decorators import (
3332
Appender,
@@ -1156,8 +1155,6 @@ def sum(
11561155
self,
11571156
numeric_only: bool = False,
11581157
min_count: int = 0,
1159-
*args,
1160-
**kwargs,
11611158
):
11621159
"""
11631160
Compute sum of group values.
@@ -1195,17 +1192,13 @@ def sum(
11951192
2023-02-01 7
11961193
Freq: MS, dtype: int64
11971194
"""
1198-
maybe_warn_args_and_kwargs(type(self), "sum", args, kwargs)
1199-
nv.validate_resampler_func("sum", args, kwargs)
12001195
return self._downsample("sum", numeric_only=numeric_only, min_count=min_count)
12011196

12021197
@final
12031198
def prod(
12041199
self,
12051200
numeric_only: bool = False,
12061201
min_count: int = 0,
1207-
*args,
1208-
**kwargs,
12091202
):
12101203
"""
12111204
Compute prod of group values.
@@ -1243,17 +1236,13 @@ def prod(
12431236
2023-02-01 12
12441237
Freq: MS, dtype: int64
12451238
"""
1246-
maybe_warn_args_and_kwargs(type(self), "prod", args, kwargs)
1247-
nv.validate_resampler_func("prod", args, kwargs)
12481239
return self._downsample("prod", numeric_only=numeric_only, min_count=min_count)
12491240

12501241
@final
12511242
def min(
12521243
self,
12531244
numeric_only: bool = False,
12541245
min_count: int = 0,
1255-
*args,
1256-
**kwargs,
12571246
):
12581247
"""
12591248
Compute min value of group.
@@ -1277,18 +1266,13 @@ def min(
12771266
2023-02-01 3
12781267
Freq: MS, dtype: int64
12791268
"""
1280-
1281-
maybe_warn_args_and_kwargs(type(self), "min", args, kwargs)
1282-
nv.validate_resampler_func("min", args, kwargs)
12831269
return self._downsample("min", numeric_only=numeric_only, min_count=min_count)
12841270

12851271
@final
12861272
def max(
12871273
self,
12881274
numeric_only: bool = False,
12891275
min_count: int = 0,
1290-
*args,
1291-
**kwargs,
12921276
):
12931277
"""
12941278
Compute max value of group.
@@ -1312,8 +1296,6 @@ def max(
13121296
2023-02-01 4
13131297
Freq: MS, dtype: int64
13141298
"""
1315-
maybe_warn_args_and_kwargs(type(self), "max", args, kwargs)
1316-
nv.validate_resampler_func("max", args, kwargs)
13171299
return self._downsample("max", numeric_only=numeric_only, min_count=min_count)
13181300

13191301
@final
@@ -1323,11 +1305,7 @@ def first(
13231305
numeric_only: bool = False,
13241306
min_count: int = 0,
13251307
skipna: bool = True,
1326-
*args,
1327-
**kwargs,
13281308
):
1329-
maybe_warn_args_and_kwargs(type(self), "first", args, kwargs)
1330-
nv.validate_resampler_func("first", args, kwargs)
13311309
return self._downsample(
13321310
"first", numeric_only=numeric_only, min_count=min_count, skipna=skipna
13331311
)
@@ -1339,28 +1317,20 @@ def last(
13391317
numeric_only: bool = False,
13401318
min_count: int = 0,
13411319
skipna: bool = True,
1342-
*args,
1343-
**kwargs,
13441320
):
1345-
maybe_warn_args_and_kwargs(type(self), "last", args, kwargs)
1346-
nv.validate_resampler_func("last", args, kwargs)
13471321
return self._downsample(
13481322
"last", numeric_only=numeric_only, min_count=min_count, skipna=skipna
13491323
)
13501324

13511325
@final
13521326
@doc(GroupBy.median)
1353-
def median(self, numeric_only: bool = False, *args, **kwargs):
1354-
maybe_warn_args_and_kwargs(type(self), "median", args, kwargs)
1355-
nv.validate_resampler_func("median", args, kwargs)
1327+
def median(self, numeric_only: bool = False):
13561328
return self._downsample("median", numeric_only=numeric_only)
13571329

13581330
@final
13591331
def mean(
13601332
self,
13611333
numeric_only: bool = False,
1362-
*args,
1363-
**kwargs,
13641334
):
13651335
"""
13661336
Compute mean of groups, excluding missing values.
@@ -1395,17 +1365,13 @@ def mean(
13951365
2023-02-01 3.5
13961366
Freq: MS, dtype: float64
13971367
"""
1398-
maybe_warn_args_and_kwargs(type(self), "mean", args, kwargs)
1399-
nv.validate_resampler_func("mean", args, kwargs)
14001368
return self._downsample("mean", numeric_only=numeric_only)
14011369

14021370
@final
14031371
def std(
14041372
self,
14051373
ddof: int = 1,
14061374
numeric_only: bool = False,
1407-
*args,
1408-
**kwargs,
14091375
):
14101376
"""
14111377
Compute standard deviation of groups, excluding missing values.
@@ -1443,17 +1409,13 @@ def std(
14431409
2023-02-01 2.645751
14441410
Freq: MS, dtype: float64
14451411
"""
1446-
maybe_warn_args_and_kwargs(type(self), "std", args, kwargs)
1447-
nv.validate_resampler_func("std", args, kwargs)
14481412
return self._downsample("std", ddof=ddof, numeric_only=numeric_only)
14491413

14501414
@final
14511415
def var(
14521416
self,
14531417
ddof: int = 1,
14541418
numeric_only: bool = False,
1455-
*args,
1456-
**kwargs,
14571419
):
14581420
"""
14591421
Compute variance of groups, excluding missing values.
@@ -1497,8 +1459,6 @@ def var(
14971459
2023-02-01 4.666667
14981460
Freq: MS, dtype: float64
14991461
"""
1500-
maybe_warn_args_and_kwargs(type(self), "var", args, kwargs)
1501-
nv.validate_resampler_func("var", args, kwargs)
15021462
return self._downsample("var", ddof=ddof, numeric_only=numeric_only)
15031463

15041464
@final
@@ -1507,23 +1467,12 @@ def sem(
15071467
self,
15081468
ddof: int = 1,
15091469
numeric_only: bool = False,
1510-
*args,
1511-
**kwargs,
15121470
):
1513-
maybe_warn_args_and_kwargs(type(self), "sem", args, kwargs)
1514-
nv.validate_resampler_func("sem", args, kwargs)
15151471
return self._downsample("sem", ddof=ddof, numeric_only=numeric_only)
15161472

15171473
@final
15181474
@doc(GroupBy.ohlc)
1519-
def ohlc(
1520-
self,
1521-
*args,
1522-
**kwargs,
1523-
):
1524-
maybe_warn_args_and_kwargs(type(self), "ohlc", args, kwargs)
1525-
nv.validate_resampler_func("ohlc", args, kwargs)
1526-
1475+
def ohlc(self):
15271476
ax = self.ax
15281477
obj = self._obj_with_exclusions
15291478
if len(ax) == 0:
@@ -1544,13 +1493,7 @@ def ohlc(
15441493

15451494
@final
15461495
@doc(SeriesGroupBy.nunique)
1547-
def nunique(
1548-
self,
1549-
*args,
1550-
**kwargs,
1551-
):
1552-
maybe_warn_args_and_kwargs(type(self), "nunique", args, kwargs)
1553-
nv.validate_resampler_func("nunique", args, kwargs)
1496+
def nunique(self):
15541497
return self._downsample("nunique")
15551498

15561499
@final
@@ -2874,40 +2817,6 @@ def _asfreq_compat(index: DatetimeIndex | PeriodIndex | TimedeltaIndex, freq):
28742817
return new_index
28752818

28762819

2877-
def maybe_warn_args_and_kwargs(cls, kernel: str, args, kwargs) -> None:
2878-
"""
2879-
Warn for deprecation of args and kwargs in resample functions.
2880-
2881-
Parameters
2882-
----------
2883-
cls : type
2884-
Class to warn about.
2885-
kernel : str
2886-
Operation name.
2887-
args : tuple or None
2888-
args passed by user. Will be None if and only if kernel does not have args.
2889-
kwargs : dict or None
2890-
kwargs passed by user. Will be None if and only if kernel does not have kwargs.
2891-
"""
2892-
warn_args = args is not None and len(args) > 0
2893-
warn_kwargs = kwargs is not None and len(kwargs) > 0
2894-
if warn_args and warn_kwargs:
2895-
msg = "args and kwargs"
2896-
elif warn_args:
2897-
msg = "args"
2898-
elif warn_kwargs:
2899-
msg = "kwargs"
2900-
else:
2901-
return
2902-
warnings.warn(
2903-
f"Passing additional {msg} to {cls.__name__}.{kernel} has "
2904-
"no impact on the result and is deprecated. This will "
2905-
"raise a TypeError in a future version of pandas.",
2906-
category=FutureWarning,
2907-
stacklevel=find_stack_level(),
2908-
)
2909-
2910-
29112820
def _apply(
29122821
grouped: GroupBy, how: Callable, *args, include_groups: bool, **kwargs
29132822
) -> DataFrame:

pandas/io/sql.py

-31
Original file line numberDiff line numberDiff line change
@@ -235,37 +235,6 @@ def _wrap_result_adbc(
235235
return df
236236

237237

238-
def execute(sql, con, params=None):
239-
"""
240-
Execute the given SQL query using the provided connection object.
241-
242-
Parameters
243-
----------
244-
sql : string
245-
SQL query to be executed.
246-
con : SQLAlchemy connection or sqlite3 connection
247-
If a DBAPI2 object, only sqlite3 is supported.
248-
params : list or tuple, optional, default: None
249-
List of parameters to pass to execute method.
250-
251-
Returns
252-
-------
253-
Results Iterable
254-
"""
255-
warnings.warn(
256-
"`pandas.io.sql.execute` is deprecated and "
257-
"will be removed in the future version.",
258-
FutureWarning,
259-
stacklevel=find_stack_level(),
260-
) # GH50185
261-
sqlalchemy = import_optional_dependency("sqlalchemy", errors="ignore")
262-
263-
if sqlalchemy is not None and isinstance(con, (str, sqlalchemy.engine.Engine)):
264-
raise TypeError("pandas.io.sql.execute requires a connection") # GH50185
265-
with pandasSQL_builder(con, need_transaction=True) as pandas_sql:
266-
return pandas_sql.execute(sql, params)
267-
268-
269238
# -----------------------------------------------------------------------------
270239
# -- Read and write to DataFrames
271240

pandas/tests/io/test_sql.py

-20
Original file line numberDiff line numberDiff line change
@@ -1487,26 +1487,6 @@ def test_read_view_sqlite(sqlite_buildin):
14871487
tm.assert_frame_equal(result, expected)
14881488

14891489

1490-
def test_execute_typeerror(sqlite_engine_iris):
1491-
with pytest.raises(TypeError, match="pandas.io.sql.execute requires a connection"):
1492-
with tm.assert_produces_warning(
1493-
FutureWarning,
1494-
match="`pandas.io.sql.execute` is deprecated and "
1495-
"will be removed in the future version.",
1496-
):
1497-
sql.execute("select * from iris", sqlite_engine_iris)
1498-
1499-
1500-
def test_execute_deprecated(sqlite_conn_iris):
1501-
# GH50185
1502-
with tm.assert_produces_warning(
1503-
FutureWarning,
1504-
match="`pandas.io.sql.execute` is deprecated and "
1505-
"will be removed in the future version.",
1506-
):
1507-
sql.execute("select * from iris", sqlite_conn_iris)
1508-
1509-
15101490
def flavor(conn_name):
15111491
if "postgresql" in conn_name:
15121492
return "postgresql"

pandas/tests/resample/test_resample_api.py

-41
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import pytest
66

77
from pandas._libs import lib
8-
from pandas.errors import UnsupportedFunctionCall
98

109
import pandas as pd
1110
from pandas import (
@@ -987,46 +986,6 @@ def test_series_downsample_method(method, numeric_only, expected_data):
987986
tm.assert_series_equal(result, expected)
988987

989988

990-
@pytest.mark.parametrize(
991-
"method, raises",
992-
[
993-
("sum", True),
994-
("prod", True),
995-
("min", True),
996-
("max", True),
997-
("first", False),
998-
("last", False),
999-
("median", False),
1000-
("mean", True),
1001-
("std", True),
1002-
("var", True),
1003-
("sem", False),
1004-
("ohlc", False),
1005-
("nunique", False),
1006-
],
1007-
)
1008-
def test_args_kwargs_depr(method, raises):
1009-
index = date_range("20180101", periods=3, freq="h")
1010-
df = Series([2, 4, 6], index=index)
1011-
resampled = df.resample("30min")
1012-
args = ()
1013-
1014-
func = getattr(resampled, method)
1015-
1016-
error_msg = "numpy operations are not valid with resample."
1017-
error_msg_type = "too many arguments passed in"
1018-
warn_msg = f"Passing additional args to DatetimeIndexResampler.{method}"
1019-
1020-
if raises:
1021-
with tm.assert_produces_warning(FutureWarning, match=warn_msg):
1022-
with pytest.raises(UnsupportedFunctionCall, match=error_msg):
1023-
func(*args, 1, 2, 3, 4)
1024-
else:
1025-
with tm.assert_produces_warning(FutureWarning, match=warn_msg):
1026-
with pytest.raises(TypeError, match=error_msg_type):
1027-
func(*args, 1, 2, 3, 4)
1028-
1029-
1030989
def test_resample_empty():
1031990
# GH#52484
1032991
df = DataFrame(

0 commit comments

Comments
 (0)