Skip to content

Commit 9fd85bb

Browse files
committed
DEPR: Deprecate PeriodIndex.to_datetime.
Deprecation is in favour of PeriodIndex.to_timestamp.
1 parent d91cec4 commit 9fd85bb

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

doc/source/whatsnew/v0.19.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ Deprecations
10611061
- ``Categorical.reshape`` has been deprecated and will be removed in a subsequent release (:issue:`12882`)
10621062
- ``Series.reshape`` has been deprecated and will be removed in a subsequent release (:issue:`12882`)
10631063

1064+
- ``PeriodIndex.to_datetime`` has been deprecated in favour of ``PeriodIndex.to_timestamp`` (:issue:`8254`)
10641065
- ``Timestamp.to_datetime`` has been deprecated in favour of ``Timestamp.to_pydatetime`` (:issue:`8254`)
10651066
- ``Index.to_datetime`` and ``DatetimeIndex.to_datetime`` have been deprecated in favour of ``pd.to_datetime`` (:issue:`8254`)
10661067
- ``SparseList`` has been deprecated and will be removed in a future version (:issue:`13784`)

pandas/tests/frame/test_to_csv.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def _to_uni(x):
294294
list(map(Timestamp, to_datetime(recons.index))),
295295
dtype=r_dtype)
296296
df.index = np.array(
297-
list(map(Timestamp, df.index.to_datetime())),
297+
list(map(Timestamp, df.index.to_timestamp())),
298298
dtype=r_dtype)
299299
else:
300300
r_dtype = type_map.get(r_dtype)
@@ -319,7 +319,7 @@ def _to_uni(x):
319319
lmap(Timestamp, to_datetime(recons.columns)),
320320
dtype=c_dtype)
321321
df.columns = np.array(
322-
lmap(Timestamp, df.columns.to_datetime()),
322+
lmap(Timestamp, df.columns.to_timestamp()),
323323
dtype=c_dtype)
324324
else:
325325
c_dtype = type_map.get(c_dtype)

pandas/tseries/period.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# pylint: disable=E1101,E1103,W0232
22
from datetime import datetime, timedelta
33
import numpy as np
4+
import warnings
45

56

67
from pandas.core import common as com
@@ -550,6 +551,13 @@ def asfreq(self, freq=None, how='E'):
550551
return self._simple_new(new_data, self.name, freq=freq)
551552

552553
def to_datetime(self, dayfirst=False):
554+
"""
555+
DEPRECATED: use :meth:`to_timestamp` instead.
556+
557+
Cast to DatetimeIndex.
558+
"""
559+
warnings.warn("to_datetime is deprecated. Use self.to_timestamp(...)",
560+
FutureWarning, stacklevel=2)
553561
return self.to_timestamp()
554562

555563
year = _field_accessor('year', 0, "The year of the period")

pandas/tseries/tests/test_period.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -3560,12 +3560,20 @@ def test_with_multi_index(self):
35603560

35613561
tm.assertIsInstance(s.index.values[0][0], Period)
35623562

3563-
def test_to_datetime_1703(self):
3563+
def test_to_timestamp_1703(self):
35643564
index = period_range('1/1/2012', periods=4, freq='D')
35653565

3566-
result = index.to_datetime()
3566+
result = index.to_timestamp()
35673567
self.assertEqual(result[0], Timestamp('1/1/2012'))
35683568

3569+
def test_to_datetime_depr(self):
3570+
index = period_range('1/1/2012', periods=4, freq='D')
3571+
3572+
with tm.assert_produces_warning(FutureWarning,
3573+
check_stacklevel=False):
3574+
result = index.to_datetime()
3575+
self.assertEqual(result[0], Timestamp('1/1/2012'))
3576+
35693577
def test_get_loc_msg(self):
35703578
idx = period_range('2000-1-1', freq='A', periods=10)
35713579
bad_period = Period('2012', 'A')

0 commit comments

Comments
 (0)