Skip to content

Commit 4b73f22

Browse files
jquinongfyoung
authored andcommitted
CLN: Remove PeriodIndex.tz_convert, tz_localize (#21935)
CLN: Removed tz_convert and tz_localize from PeriodIndex Closes gh-21781
1 parent ce87d06 commit 4b73f22

File tree

4 files changed

+1
-58
lines changed

4 files changed

+1
-58
lines changed

doc/source/api.rst

-2
Original file line numberDiff line numberDiff line change
@@ -1870,8 +1870,6 @@ Methods
18701870
PeriodIndex.asfreq
18711871
PeriodIndex.strftime
18721872
PeriodIndex.to_timestamp
1873-
PeriodIndex.tz_convert
1874-
PeriodIndex.tz_localize
18751873

18761874
Scalars
18771875
-------

doc/source/whatsnew/v0.24.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ Other API Changes
309309
a ``KeyError`` (:issue:`21678`).
310310
- Invalid construction of ``IntervalDtype`` will now always raise a ``TypeError`` rather than a ``ValueError`` if the subdtype is invalid (:issue:`21185`)
311311
- Trying to reindex a ``DataFrame`` with a non unique ``MultiIndex`` now raises a ``ValueError`` instead of an ``Exception`` (:issue:`21770`)
312-
-
312+
- :meth:`PeriodIndex.tz_convert` and :meth:`PeriodIndex.tz_localize` have been removed (:issue:`21781`)
313313

314314
.. _whatsnew_0240.deprecations:
315315

pandas/core/indexes/period.py

-46
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ class PeriodIndex(PeriodArrayMixin, DatelikeOps, DatetimeIndexOpsMixin,
140140
asfreq
141141
strftime
142142
to_timestamp
143-
tz_convert
144-
tz_localize
145143
146144
Examples
147145
--------
@@ -805,50 +803,6 @@ def __setstate__(self, state):
805803

806804
_unpickle_compat = __setstate__
807805

808-
def tz_convert(self, tz):
809-
"""
810-
Convert tz-aware DatetimeIndex from one time zone to another (using
811-
pytz/dateutil)
812-
813-
Parameters
814-
----------
815-
tz : string, pytz.timezone, dateutil.tz.tzfile or None
816-
Time zone for time. Corresponding timestamps would be converted to
817-
time zone of the TimeSeries.
818-
None will remove timezone holding UTC time.
819-
820-
Returns
821-
-------
822-
normalized : DatetimeIndex
823-
824-
Notes
825-
-----
826-
Not currently implemented for PeriodIndex
827-
"""
828-
raise NotImplementedError("Not yet implemented for PeriodIndex")
829-
830-
def tz_localize(self, tz, ambiguous='raise'):
831-
"""
832-
Localize tz-naive DatetimeIndex to given time zone (using
833-
pytz/dateutil), or remove timezone from tz-aware DatetimeIndex
834-
835-
Parameters
836-
----------
837-
tz : string, pytz.timezone, dateutil.tz.tzfile or None
838-
Time zone for time. Corresponding timestamps would be converted to
839-
time zone of the TimeSeries.
840-
None will remove timezone holding local time.
841-
842-
Returns
843-
-------
844-
localized : DatetimeIndex
845-
846-
Notes
847-
-----
848-
Not currently implemented for PeriodIndex
849-
"""
850-
raise NotImplementedError("Not yet implemented for PeriodIndex")
851-
852806

853807
PeriodIndex._add_comparison_methods()
854808
PeriodIndex._add_numeric_methods_disabled()

pandas/tests/frame/test_timeseries.py

-9
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,6 @@ def test_datetime_assignment_with_NaT_and_diff_time_units(self):
747747

748748
def test_frame_to_period(self):
749749
K = 5
750-
from pandas.core.indexes.period import period_range
751750

752751
dr = date_range('1/1/2000', '1/1/2001')
753752
pr = period_range('1/1/2000', '1/1/2001')
@@ -776,14 +775,6 @@ def test_frame_to_period(self):
776775
@pytest.mark.parametrize("fn", ['tz_localize', 'tz_convert'])
777776
def test_tz_convert_and_localize(self, fn):
778777
l0 = date_range('20140701', periods=5, freq='D')
779-
780-
# TODO: l1 should be a PeriodIndex for testing
781-
# after GH2106 is addressed
782-
with pytest.raises(NotImplementedError):
783-
period_range('20140701', periods=1).tz_convert('UTC')
784-
with pytest.raises(NotImplementedError):
785-
period_range('20140701', periods=1).tz_localize('UTC')
786-
# l1 = period_range('20140701', periods=5, freq='D')
787778
l1 = date_range('20140701', periods=5, freq='D')
788779

789780
int_idx = Index(range(5))

0 commit comments

Comments
 (0)