Skip to content

Commit 7ce6765

Browse files
committed
CLN: Remove .to_datetime methods
Removes the following .to_datetime methods * Index.to_datetime * Timestamp.to_datetime * PeriodIndex.to_datetime * DatetimeIndex.to_datetime All were deprecated in 0.19.0 xref pandas-devgh-8254, pandas-devgh-14096, pandas-devgh-14113
1 parent c3c04e2 commit 7ce6765

File tree

9 files changed

+1
-88
lines changed

9 files changed

+1
-88
lines changed

doc/source/api.rst

-2
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,6 @@ Conversion
14891489
Index.map
14901490
Index.ravel
14911491
Index.tolist
1492-
Index.to_datetime
14931492
Index.to_native_types
14941493
Index.to_series
14951494
Index.to_frame
@@ -1757,7 +1756,6 @@ Conversion
17571756
.. autosummary::
17581757
:toctree: generated/
17591758

1760-
DatetimeIndex.to_datetime
17611759
DatetimeIndex.to_period
17621760
DatetimeIndex.to_perioddelta
17631761
DatetimeIndex.to_pydatetime

doc/source/whatsnew/v0.22.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ Removal of prior version deprecations/changes
150150
- The ``SparseList`` class has been removed (:issue:`14007`)
151151
- The ``pandas.io.wb`` and ``pandas.io.data`` stub modules have been removed (:issue:`13735`)
152152
- ``Categorical.from_array`` has been removed (:issue:`13854`)
153+
- ``DatetimeIndex.to_datetime``, ``Timestamp.to_datetime``, ``PeriodIndex.to_datetime``, and ``Index.to_datetime`` have been removed (:issue:`8254`, :issue:`14096`, :issue:`14113`)
153154

154155
.. _whatsnew_0220.performance:
155156

pandas/_libs/tslibs/timestamps.pyx

-10
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,6 @@ cdef class _Timestamp(datetime):
181181
elif other.tzinfo is None:
182182
raise TypeError('Cannot compare tz-naive and tz-aware timestamps')
183183

184-
cpdef datetime to_datetime(_Timestamp self):
185-
"""
186-
DEPRECATED: use :meth:`to_pydatetime` instead.
187-
188-
Convert a Timestamp object to a native Python datetime object.
189-
"""
190-
warnings.warn("to_datetime is deprecated. Use self.to_pydatetime()",
191-
FutureWarning, stacklevel=2)
192-
return self.to_pydatetime(warn=False)
193-
194184
cpdef datetime to_pydatetime(_Timestamp self, warn=True):
195185
"""
196186
Convert a Timestamp object to a native Python datetime object.

pandas/core/indexes/base.py

-19
Original file line numberDiff line numberDiff line change
@@ -1061,25 +1061,6 @@ def _to_safe_for_reshape(self):
10611061
""" convert to object if we are a categorical """
10621062
return self
10631063

1064-
def to_datetime(self, dayfirst=False):
1065-
"""
1066-
DEPRECATED: use :meth:`pandas.to_datetime` instead.
1067-
1068-
For an Index containing strings or datetime.datetime objects, attempt
1069-
conversion to DatetimeIndex
1070-
"""
1071-
warnings.warn("to_datetime is deprecated. Use pd.to_datetime(...)",
1072-
FutureWarning, stacklevel=2)
1073-
1074-
from pandas.core.indexes.datetimes import DatetimeIndex
1075-
if self.inferred_type == 'string':
1076-
from dateutil.parser import parse
1077-
parser = lambda x: parse(x, dayfirst=dayfirst)
1078-
parsed = parsing.try_parse_dates(self.values, parser=parser)
1079-
return DatetimeIndex(parsed)
1080-
else:
1081-
return DatetimeIndex(self.values)
1082-
10831064
def _assert_can_do_setop(self, other):
10841065
if not is_list_like(other):
10851066
raise TypeError('Input must be Index or array-like')

pandas/core/indexes/datetimes.py

-4
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ class DatetimeIndex(DatelikeOps, TimelikeOps, DatetimeIndexOpsMixin,
244244
round
245245
floor
246246
ceil
247-
to_datetime
248247
to_period
249248
to_perioddelta
250249
to_pydatetime
@@ -899,9 +898,6 @@ def _format_native_types(self, na_rep='NaT', date_format=None, **kwargs):
899898
format=format,
900899
na_rep=na_rep)
901900

902-
def to_datetime(self, dayfirst=False):
903-
return self.copy()
904-
905901
@Appender(_index_shared_docs['astype'])
906902
def astype(self, dtype, copy=True):
907903
dtype = pandas_dtype(dtype)

pandas/core/indexes/period.py

-11
Original file line numberDiff line numberDiff line change
@@ -611,17 +611,6 @@ def asfreq(self, freq=None, how='E'):
611611

612612
return self._simple_new(new_data, self.name, freq=freq)
613613

614-
def to_datetime(self, dayfirst=False):
615-
"""
616-
.. deprecated:: 0.19.0
617-
Use :meth:`to_timestamp` instead.
618-
619-
Cast to DatetimeIndex.
620-
"""
621-
warnings.warn("to_datetime is deprecated. Use self.to_timestamp(...)",
622-
FutureWarning, stacklevel=2)
623-
return self.to_timestamp()
624-
625614
year = _field_accessor('year', 0, "The year of the period")
626615
month = _field_accessor('month', 3, "The month as January=1, December=12")
627616
day = _field_accessor('day', 4, "The days of the period")

pandas/tests/indexes/datetimes/test_tools.py

-24
Original file line numberDiff line numberDiff line change
@@ -735,24 +735,6 @@ def test_dataframe_dtypes(self, cache):
735735

736736
class TestToDatetimeMisc(object):
737737

738-
@pytest.mark.parametrize('cache', [True, False])
739-
def test_index_to_datetime(self, cache):
740-
idx = Index(['1/1/2000', '1/2/2000', '1/3/2000'])
741-
742-
with tm.assert_produces_warning(FutureWarning,
743-
check_stacklevel=False):
744-
result = idx.to_datetime()
745-
expected = DatetimeIndex(pd.to_datetime(idx.values, cache=cache))
746-
tm.assert_index_equal(result, expected)
747-
748-
with tm.assert_produces_warning(FutureWarning,
749-
check_stacklevel=False):
750-
today = datetime.today()
751-
idx = Index([today], dtype=object)
752-
result = idx.to_datetime()
753-
expected = DatetimeIndex([today])
754-
tm.assert_index_equal(result, expected)
755-
756738
@pytest.mark.parametrize('cache', [True, False])
757739
def test_to_datetime_iso8601(self, cache):
758740
result = to_datetime(["2012-01-01 00:00:00"], cache=cache)
@@ -888,12 +870,6 @@ def test_to_datetime_list_of_integers(self):
888870

889871
tm.assert_index_equal(rng, result)
890872

891-
def test_to_datetime_freq(self):
892-
xp = bdate_range('2000-1-1', periods=10, tz='UTC')
893-
rs = xp.to_datetime()
894-
assert xp.freq == rs.freq
895-
assert xp.tzinfo == rs.tzinfo
896-
897873
def test_to_datetime_overflow(self):
898874
# gh-17637
899875
# we are overflowing Timedelta range here

pandas/tests/indexes/period/test_tools.py

-8
Original file line numberDiff line numberDiff line change
@@ -386,14 +386,6 @@ def test_to_timestamp_1703(self):
386386
result = index.to_timestamp()
387387
assert result[0] == Timestamp('1/1/2012')
388388

389-
def test_to_datetime_depr(self):
390-
index = period_range('1/1/2012', periods=4, freq='D')
391-
392-
with tm.assert_produces_warning(FutureWarning,
393-
check_stacklevel=False):
394-
result = index.to_datetime()
395-
assert result[0] == Timestamp('1/1/2012')
396-
397389
def test_combine_first(self):
398390
# GH 3367
399391
didx = pd.DatetimeIndex(start='1950-01-31', end='1950-07-31', freq='M')

pandas/tests/scalar/test_timestamp.py

-10
Original file line numberDiff line numberDiff line change
@@ -672,16 +672,6 @@ def test_pprint(self):
672672
'foo': 1}"""
673673
assert result == expected
674674

675-
def test_to_datetime_depr(self):
676-
# see gh-8254
677-
ts = Timestamp('2011-01-01')
678-
679-
with tm.assert_produces_warning(FutureWarning,
680-
check_stacklevel=False):
681-
expected = datetime(2011, 1, 1)
682-
result = ts.to_datetime()
683-
assert result == expected
684-
685675
def test_to_pydatetime_nonzero_nano(self):
686676
ts = Timestamp('2011-01-01 9:00:00.123456789')
687677

0 commit comments

Comments
 (0)