Skip to content

DEPR: Enforce deprecation of parsing to tzlocal #58002

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 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ Removal of prior version deprecations/changes
- 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`)
- Enforced deprecation of :meth:`Series.interpolate` and :meth:`DataFrame.interpolate` for object-dtype (:issue:`57820`)
- 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`)
- Enforced deprecation of parsing system timezone strings to ``tzlocal``, which depended on system timezone, pass the 'tz' keyword instead (:issue:`50791`)
- Enforced deprecation of passing a dictionary to :meth:`SeriesGroupBy.agg` (:issue:`52268`)
- 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`)
- 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`)
Expand Down
12 changes: 3 additions & 9 deletions pandas/_libs/tslibs/parsing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ from decimal import InvalidOperation

from dateutil.parser import DEFAULTPARSER
from dateutil.tz import (
tzlocal as _dateutil_tzlocal,
tzoffset,
tzutc as _dateutil_tzutc,
)
Expand Down Expand Up @@ -703,17 +702,12 @@ cdef datetime dateutil_parse(
if res.tzname and res.tzname in time.tzname:
# GH#50791
if res.tzname != "UTC":
# If the system is localized in UTC (as many CI runs are)
# we get tzlocal, once the deprecation is enforced will get
# timezone.utc, not raise.
warnings.warn(
raise ValueError(
f"Parsing '{res.tzname}' as tzlocal (dependent on system timezone) "
"is deprecated and will raise in a future version. Pass the 'tz' "
"is no longer supported. Pass the 'tz' "
"keyword or call tz_localize after construction instead",
FutureWarning,
stacklevel=find_stack_level()
)
ret = ret.replace(tzinfo=_dateutil_tzlocal())
ret = ret.replace(tzinfo=timezone.utc)
elif res.tzoffset == 0:
ret = ret.replace(tzinfo=_dateutil_tzutc())
elif res.tzoffset:
Expand Down
20 changes: 12 additions & 8 deletions pandas/tests/tslibs/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import re

from dateutil.parser import parse as du_parse
from dateutil.tz import tzlocal
from hypothesis import given
import numpy as np
import pytest
Expand All @@ -22,6 +21,10 @@
)
import pandas.util._test_decorators as td

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

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

with tm.set_timezone("US/Eastern"):
with tm.assert_produces_warning(FutureWarning, match=msg):
res, _ = parse_datetime_string_with_reso(dtstr)
with pytest.raises(ValueError, match=msg):
parse_datetime_string_with_reso(dtstr)

assert isinstance(res.tzinfo, tzlocal)
with pytest.raises(ValueError, match=msg):
parsing.py_parse_datetime_string(dtstr)

with tm.assert_produces_warning(FutureWarning, match=msg):
res = parsing.py_parse_datetime_string(dtstr)
assert isinstance(res.tzinfo, tzlocal)
with pytest.raises(ValueError, match=msg):
Timestamp(dtstr)


def test_parse_datetime_string_with_reso():
Expand Down
Loading