Skip to content

Commit 069f9a4

Browse files
authored
DEPR: Enforce deprecation of parsing to tzlocal (pandas-dev#58002)
1 parent d0e771b commit 069f9a4

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ Removal of prior version deprecations/changes
202202
- Enforced deprecation of :meth:`.DataFrameGroupBy.get_group` and :meth:`.SeriesGroupBy.get_group` allowing the ``name`` argument to be a non-tuple when grouping by a list of length 1 (:issue:`54155`)
203203
- Enforced deprecation of :meth:`Series.interpolate` and :meth:`DataFrame.interpolate` for object-dtype (:issue:`57820`)
204204
- Enforced deprecation of ``axis=None`` acting the same as ``axis=0`` in the DataFrame reductions ``sum``, ``prod``, ``std``, ``var``, and ``sem``, passing ``axis=None`` will now reduce over both axes; this is particularly the case when doing e.g. ``numpy.sum(df)`` (:issue:`21597`)
205+
- Enforced deprecation of parsing system timezone strings to ``tzlocal``, which depended on system timezone, pass the 'tz' keyword instead (:issue:`50791`)
205206
- Enforced deprecation of passing a dictionary to :meth:`SeriesGroupBy.agg` (:issue:`52268`)
206207
- Enforced deprecation of string ``AS`` denoting frequency in :class:`YearBegin` and strings ``AS-DEC``, ``AS-JAN``, etc. denoting annual frequencies with various fiscal year starts (:issue:`57793`)
207208
- Enforced deprecation of string ``A`` denoting frequency in :class:`YearEnd` and strings ``A-DEC``, ``A-JAN``, etc. denoting annual frequencies with various fiscal year ends (:issue:`57699`)

pandas/_libs/tslibs/parsing.pyx

+3-9
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ from decimal import InvalidOperation
4545

4646
from dateutil.parser import DEFAULTPARSER
4747
from dateutil.tz import (
48-
tzlocal as _dateutil_tzlocal,
4948
tzoffset,
5049
tzutc as _dateutil_tzutc,
5150
)
@@ -703,17 +702,12 @@ cdef datetime dateutil_parse(
703702
if res.tzname and res.tzname in time.tzname:
704703
# GH#50791
705704
if res.tzname != "UTC":
706-
# If the system is localized in UTC (as many CI runs are)
707-
# we get tzlocal, once the deprecation is enforced will get
708-
# timezone.utc, not raise.
709-
warnings.warn(
705+
raise ValueError(
710706
f"Parsing '{res.tzname}' as tzlocal (dependent on system timezone) "
711-
"is deprecated and will raise in a future version. Pass the 'tz' "
707+
"is no longer supported. Pass the 'tz' "
712708
"keyword or call tz_localize after construction instead",
713-
FutureWarning,
714-
stacklevel=find_stack_level()
715709
)
716-
ret = ret.replace(tzinfo=_dateutil_tzlocal())
710+
ret = ret.replace(tzinfo=timezone.utc)
717711
elif res.tzoffset == 0:
718712
ret = ret.replace(tzinfo=_dateutil_tzutc())
719713
elif res.tzoffset:

pandas/tests/tslibs/test_parsing.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import re
77

88
from dateutil.parser import parse as du_parse
9-
from dateutil.tz import tzlocal
109
from hypothesis import given
1110
import numpy as np
1211
import pytest
@@ -22,6 +21,10 @@
2221
)
2322
import pandas.util._test_decorators as td
2423

24+
# Usually we wouldn't want this import in this test file (which is targeted at
25+
# tslibs.parsing), but it is convenient to test the Timestamp constructor at
26+
# the same time as the other parsing functions.
27+
from pandas import Timestamp
2528
import pandas._testing as tm
2629
from pandas._testing._hypothesis import DATETIME_NO_TZ
2730

@@ -33,20 +36,21 @@
3336
def test_parsing_tzlocal_deprecated():
3437
# GH#50791
3538
msg = (
36-
"Parsing 'EST' as tzlocal.*"
39+
r"Parsing 'EST' as tzlocal \(dependent on system timezone\) "
40+
r"is no longer supported\. "
3741
"Pass the 'tz' keyword or call tz_localize after construction instead"
3842
)
3943
dtstr = "Jan 15 2004 03:00 EST"
4044

4145
with tm.set_timezone("US/Eastern"):
42-
with tm.assert_produces_warning(FutureWarning, match=msg):
43-
res, _ = parse_datetime_string_with_reso(dtstr)
46+
with pytest.raises(ValueError, match=msg):
47+
parse_datetime_string_with_reso(dtstr)
4448

45-
assert isinstance(res.tzinfo, tzlocal)
49+
with pytest.raises(ValueError, match=msg):
50+
parsing.py_parse_datetime_string(dtstr)
4651

47-
with tm.assert_produces_warning(FutureWarning, match=msg):
48-
res = parsing.py_parse_datetime_string(dtstr)
49-
assert isinstance(res.tzinfo, tzlocal)
52+
with pytest.raises(ValueError, match=msg):
53+
Timestamp(dtstr)
5054

5155

5256
def test_parse_datetime_string_with_reso():

0 commit comments

Comments
 (0)