Skip to content
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

DEPR: tz arg in Period.to_timestamp #49280

Merged
merged 1 commit into from
Oct 24, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ Removal of prior version deprecations/changes
- Removed :meth:`MultiIndex.is_lexsorted` and :meth:`MultiIndex.lexsort_depth` (:issue:`38701`)
- Removed argument ``how`` from :meth:`PeriodIndex.astype`, use :meth:`PeriodIndex.to_timestamp` instead (:issue:`37982`)
- Removed argument ``try_cast`` from :meth:`DataFrame.mask`, :meth:`DataFrame.where`, :meth:`Series.mask` and :meth:`Series.where` (:issue:`38836`)
- Removed argument ``tz`` from :meth:`Period.to_timestamp`, use ``obj.to_timestamp(...).tz_localize(tz)`` instead (:issue:`34522`)
- Removed argument ``is_copy`` from :meth:`DataFrame.take` and :meth:`Series.take` (:issue:`30615`)
- Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`)
- Remove keywords ``convert_float`` and ``mangle_dupe_cols`` from :func:`read_excel` (:issue:`41176`)
Expand Down
2 changes: 0 additions & 2 deletions pandas/_libs/tslibs/period.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ from pandas._libs.tslibs.offsets import BaseOffset
from pandas._libs.tslibs.timestamps import Timestamp
from pandas._typing import (
Frequency,
Timezone,
npt,
)

Expand Down Expand Up @@ -88,7 +87,6 @@ class Period(PeriodMixin):
self,
freq: str | BaseOffset | None = ...,
how: str = ...,
tz: Timezone | None = ...,
) -> Timestamp: ...
def asfreq(self, freq: str | BaseOffset, how: str = ...) -> Period: ...
@property
Expand Down
18 changes: 2 additions & 16 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import warnings

from pandas.util._exceptions import find_stack_level

cimport numpy as cnp
from cpython.object cimport (
Py_EQ,
Expand Down Expand Up @@ -1802,7 +1798,7 @@ cdef class _Period(PeriodMixin):

return Period(ordinal=ordinal, freq=freq)

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

Expand All @@ -1822,16 +1818,6 @@ cdef class _Period(PeriodMixin):
-------
Timestamp
"""
if tz is not None:
# GH#34522
warnings.warn(
"Period.to_timestamp `tz` argument is deprecated and will "
"be removed in a future version. Use "
"`per.to_timestamp(...).tz_localize(tz)` instead.",
FutureWarning,
stacklevel=find_stack_level(),
)

how = validate_end_alias(how)

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

dt64 = period_ordinal_to_dt64(val.ordinal, base)
return Timestamp(dt64, tz=tz)
return Timestamp(dt64)

@property
def year(self) -> int:
Expand Down
69 changes: 0 additions & 69 deletions pandas/tests/scalar/period/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import numpy as np
import pytest
import pytz

from pandas._libs.tslibs import (
iNaT,
Expand All @@ -22,10 +21,6 @@
INVALID_FREQ_ERR_MSG,
IncompatibleFrequency,
)
from pandas._libs.tslibs.timezones import (
dateutil_gettz,
maybe_get_tz,
)

import pandas as pd
from pandas import (
Expand Down Expand Up @@ -583,70 +578,6 @@ def test_hash(self):
# --------------------------------------------------------------
# to_timestamp

@pytest.mark.parametrize("tzstr", ["Europe/Brussels", "Asia/Tokyo", "US/Pacific"])
def test_to_timestamp_tz_arg(self, tzstr):
# GH#34522 tz kwarg deprecated
with tm.assert_produces_warning(FutureWarning):
p = Period("1/1/2005", freq="M").to_timestamp(tz=tzstr)
exp = Timestamp("1/1/2005", tz="UTC").tz_convert(tzstr)
exp_zone = pytz.timezone(tzstr).normalize(p)

assert p == exp
assert p.tz == exp_zone.tzinfo
assert p.tz == exp.tz

with tm.assert_produces_warning(FutureWarning):
p = Period("1/1/2005", freq="3H").to_timestamp(tz=tzstr)
exp = Timestamp("1/1/2005", tz="UTC").tz_convert(tzstr)
exp_zone = pytz.timezone(tzstr).normalize(p)

assert p == exp
assert p.tz == exp_zone.tzinfo
assert p.tz == exp.tz

with tm.assert_produces_warning(FutureWarning):
p = Period("1/1/2005", freq="A").to_timestamp(freq="A", tz=tzstr)
exp = Timestamp(day=31, month=12, year=2005, tz="UTC").tz_convert(tzstr)
exp_zone = pytz.timezone(tzstr).normalize(p)

assert p == exp
assert p.tz == exp_zone.tzinfo
assert p.tz == exp.tz

with tm.assert_produces_warning(FutureWarning):
p = Period("1/1/2005", freq="A").to_timestamp(freq="3H", tz=tzstr)
exp = Timestamp("1/1/2005", tz="UTC").tz_convert(tzstr)
exp_zone = pytz.timezone(tzstr).normalize(p)

assert p == exp
assert p.tz == exp_zone.tzinfo
assert p.tz == exp.tz

@pytest.mark.parametrize(
"tzstr",
["dateutil/Europe/Brussels", "dateutil/Asia/Tokyo", "dateutil/US/Pacific"],
)
def test_to_timestamp_tz_arg_dateutil(self, tzstr):
tz = maybe_get_tz(tzstr)
with tm.assert_produces_warning(FutureWarning):
p = Period("1/1/2005", freq="M").to_timestamp(tz=tz)
exp = Timestamp("1/1/2005", tz="UTC").tz_convert(tzstr)
assert p == exp
assert p.tz == dateutil_gettz(tzstr.split("/", 1)[1])
assert p.tz == exp.tz

with tm.assert_produces_warning(FutureWarning):
p = Period("1/1/2005", freq="M").to_timestamp(freq="3H", tz=tz)
exp = Timestamp("1/1/2005", tz="UTC").tz_convert(tzstr)
assert p == exp
assert p.tz == dateutil_gettz(tzstr.split("/", 1)[1])
assert p.tz == exp.tz

def test_to_timestamp_tz_arg_dateutil_from_string(self):
with tm.assert_produces_warning(FutureWarning):
p = Period("1/1/2005", freq="M").to_timestamp(tz="dateutil/Europe/Brussels")
assert p.tz == dateutil_gettz("Europe/Brussels")

def test_to_timestamp_mult(self):
p = Period("2011-01", freq="M")
assert p.to_timestamp(how="S") == Timestamp("2011-01-01")
Expand Down