Skip to content

Commit e542968

Browse files
jbrockmendelnoatamir
authored andcommitted
DEPR: tz arg in Period.to_timestamp (pandas-dev#49280)
1 parent e311c12 commit e542968

File tree

4 files changed

+3
-87
lines changed

4 files changed

+3
-87
lines changed

doc/source/whatsnew/v2.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ Removal of prior version deprecations/changes
181181
- Removed :meth:`MultiIndex.is_lexsorted` and :meth:`MultiIndex.lexsort_depth` (:issue:`38701`)
182182
- Removed argument ``how`` from :meth:`PeriodIndex.astype`, use :meth:`PeriodIndex.to_timestamp` instead (:issue:`37982`)
183183
- Removed argument ``try_cast`` from :meth:`DataFrame.mask`, :meth:`DataFrame.where`, :meth:`Series.mask` and :meth:`Series.where` (:issue:`38836`)
184+
- Removed argument ``tz`` from :meth:`Period.to_timestamp`, use ``obj.to_timestamp(...).tz_localize(tz)`` instead (:issue:`34522`)
184185
- Removed argument ``is_copy`` from :meth:`DataFrame.take` and :meth:`Series.take` (:issue:`30615`)
185186
- Removed argument ``kind`` from :meth:`Index.get_slice_bound`, :meth:`Index.slice_indexer` and :meth:`Index.slice_locs` (:issue:`41378`)
186187
- Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`)

pandas/_libs/tslibs/period.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ from pandas._libs.tslibs.offsets import BaseOffset
88
from pandas._libs.tslibs.timestamps import Timestamp
99
from pandas._typing import (
1010
Frequency,
11-
Timezone,
1211
npt,
1312
)
1413

@@ -88,7 +87,6 @@ class Period(PeriodMixin):
8887
self,
8988
freq: str | BaseOffset | None = ...,
9089
how: str = ...,
91-
tz: Timezone | None = ...,
9290
) -> Timestamp: ...
9391
def asfreq(self, freq: str | BaseOffset, how: str = ...) -> Period: ...
9492
@property

pandas/_libs/tslibs/period.pyx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import warnings
2-
3-
from pandas.util._exceptions import find_stack_level
4-
51
cimport numpy as cnp
62
from cpython.object cimport (
73
Py_EQ,
@@ -1802,7 +1798,7 @@ cdef class _Period(PeriodMixin):
18021798

18031799
return Period(ordinal=ordinal, freq=freq)
18041800

1805-
def to_timestamp(self, freq=None, how='start', tz=None) -> Timestamp:
1801+
def to_timestamp(self, freq=None, how="start") -> Timestamp:
18061802
"""
18071803
Return the Timestamp representation of the Period.
18081804

@@ -1822,16 +1818,6 @@ cdef class _Period(PeriodMixin):
18221818
-------
18231819
Timestamp
18241820
"""
1825-
if tz is not None:
1826-
# GH#34522
1827-
warnings.warn(
1828-
"Period.to_timestamp `tz` argument is deprecated and will "
1829-
"be removed in a future version. Use "
1830-
"`per.to_timestamp(...).tz_localize(tz)` instead.",
1831-
FutureWarning,
1832-
stacklevel=find_stack_level(),
1833-
)
1834-
18351821
how = validate_end_alias(how)
18361822

18371823
end = how == 'E'
@@ -1853,7 +1839,7 @@ cdef class _Period(PeriodMixin):
18531839
val = self.asfreq(freq, how)
18541840

18551841
dt64 = period_ordinal_to_dt64(val.ordinal, base)
1856-
return Timestamp(dt64, tz=tz)
1842+
return Timestamp(dt64)
18571843

18581844
@property
18591845
def year(self) -> int:

pandas/tests/scalar/period/test_period.py

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import numpy as np
88
import pytest
9-
import pytz
109

1110
from pandas._libs.tslibs import (
1211
iNaT,
@@ -22,10 +21,6 @@
2221
INVALID_FREQ_ERR_MSG,
2322
IncompatibleFrequency,
2423
)
25-
from pandas._libs.tslibs.timezones import (
26-
dateutil_gettz,
27-
maybe_get_tz,
28-
)
2924

3025
import pandas as pd
3126
from pandas import (
@@ -583,70 +578,6 @@ def test_hash(self):
583578
# --------------------------------------------------------------
584579
# to_timestamp
585580

586-
@pytest.mark.parametrize("tzstr", ["Europe/Brussels", "Asia/Tokyo", "US/Pacific"])
587-
def test_to_timestamp_tz_arg(self, tzstr):
588-
# GH#34522 tz kwarg deprecated
589-
with tm.assert_produces_warning(FutureWarning):
590-
p = Period("1/1/2005", freq="M").to_timestamp(tz=tzstr)
591-
exp = Timestamp("1/1/2005", tz="UTC").tz_convert(tzstr)
592-
exp_zone = pytz.timezone(tzstr).normalize(p)
593-
594-
assert p == exp
595-
assert p.tz == exp_zone.tzinfo
596-
assert p.tz == exp.tz
597-
598-
with tm.assert_produces_warning(FutureWarning):
599-
p = Period("1/1/2005", freq="3H").to_timestamp(tz=tzstr)
600-
exp = Timestamp("1/1/2005", tz="UTC").tz_convert(tzstr)
601-
exp_zone = pytz.timezone(tzstr).normalize(p)
602-
603-
assert p == exp
604-
assert p.tz == exp_zone.tzinfo
605-
assert p.tz == exp.tz
606-
607-
with tm.assert_produces_warning(FutureWarning):
608-
p = Period("1/1/2005", freq="A").to_timestamp(freq="A", tz=tzstr)
609-
exp = Timestamp(day=31, month=12, year=2005, tz="UTC").tz_convert(tzstr)
610-
exp_zone = pytz.timezone(tzstr).normalize(p)
611-
612-
assert p == exp
613-
assert p.tz == exp_zone.tzinfo
614-
assert p.tz == exp.tz
615-
616-
with tm.assert_produces_warning(FutureWarning):
617-
p = Period("1/1/2005", freq="A").to_timestamp(freq="3H", tz=tzstr)
618-
exp = Timestamp("1/1/2005", tz="UTC").tz_convert(tzstr)
619-
exp_zone = pytz.timezone(tzstr).normalize(p)
620-
621-
assert p == exp
622-
assert p.tz == exp_zone.tzinfo
623-
assert p.tz == exp.tz
624-
625-
@pytest.mark.parametrize(
626-
"tzstr",
627-
["dateutil/Europe/Brussels", "dateutil/Asia/Tokyo", "dateutil/US/Pacific"],
628-
)
629-
def test_to_timestamp_tz_arg_dateutil(self, tzstr):
630-
tz = maybe_get_tz(tzstr)
631-
with tm.assert_produces_warning(FutureWarning):
632-
p = Period("1/1/2005", freq="M").to_timestamp(tz=tz)
633-
exp = Timestamp("1/1/2005", tz="UTC").tz_convert(tzstr)
634-
assert p == exp
635-
assert p.tz == dateutil_gettz(tzstr.split("/", 1)[1])
636-
assert p.tz == exp.tz
637-
638-
with tm.assert_produces_warning(FutureWarning):
639-
p = Period("1/1/2005", freq="M").to_timestamp(freq="3H", tz=tz)
640-
exp = Timestamp("1/1/2005", tz="UTC").tz_convert(tzstr)
641-
assert p == exp
642-
assert p.tz == dateutil_gettz(tzstr.split("/", 1)[1])
643-
assert p.tz == exp.tz
644-
645-
def test_to_timestamp_tz_arg_dateutil_from_string(self):
646-
with tm.assert_produces_warning(FutureWarning):
647-
p = Period("1/1/2005", freq="M").to_timestamp(tz="dateutil/Europe/Brussels")
648-
assert p.tz == dateutil_gettz("Europe/Brussels")
649-
650581
def test_to_timestamp_mult(self):
651582
p = Period("2011-01", freq="M")
652583
assert p.to_timestamp(how="S") == Timestamp("2011-01-01")

0 commit comments

Comments
 (0)