Skip to content

Commit c4977d5

Browse files
committed
CLN: Remove .to_datetime methods
Removes the following .to_datetime methods * Index.to_datetime * NaTType.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 13f6267 commit c4977d5

File tree

10 files changed

+2
-104
lines changed

10 files changed

+2
-104
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
@@ -152,6 +152,7 @@ Removal of prior version deprecations/changes
152152
- ``Categorical.from_array`` has been removed (:issue:`13854`)
153153
- The ``freq`` parameter has been removed from the ``rolling``/``expanding``/``ewm`` methods of DataFrame
154154
and Series (deprecated since v0.18). Instead, resample before calling the methods. (:issue:18601)
155+
- ``DatetimeIndex.to_datetime``, ``Timestamp.to_datetime``, ``PeriodIndex.to_datetime``, and ``Index.to_datetime`` have been removed (:issue:`8254`, :issue:`14096`, :issue:`14113`)
155156

156157
.. _whatsnew_0220.performance:
157158

pandas/_libs/tslibs/nattype.pyx

-10
Original file line numberDiff line numberDiff line change
@@ -556,16 +556,6 @@ class NaTType(_NaT):
556556
Timestamp with fields replaced
557557
""")
558558

559-
def to_datetime(self):
560-
"""
561-
DEPRECATED: use :meth:`to_pydatetime` instead.
562-
563-
Convert a Timestamp object to a native Python datetime object.
564-
"""
565-
warnings.warn("to_datetime is deprecated. Use self.to_pydatetime()",
566-
FutureWarning, stacklevel=2)
567-
return self.to_pydatetime(warn=False)
568-
569559

570560
NaT = NaTType()
571561

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

-20
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
algos as libalgos, join as libjoin,
88
Timestamp, Timedelta, )
99
from pandas._libs.lib import is_datetime_array
10-
from pandas._libs.tslibs import parsing
1110

1211
from pandas.compat import range, u, set_function_name
1312
from pandas.compat.numpy import function as nv
@@ -1061,25 +1060,6 @@ def _to_safe_for_reshape(self):
10611060
""" convert to object if we are a categorical """
10621061
return self
10631062

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-
10831063
def _assert_can_do_setop(self, other):
10841064
if not is_list_like(other):
10851065
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

-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import numpy as np
44
import warnings
55

6-
76
from pandas.core import common as com
87
from pandas.core.dtypes.common import (
98
is_integer,
@@ -611,17 +610,6 @@ def asfreq(self, freq=None, how='E'):
611610

612611
return self._simple_new(new_data, self.name, freq=freq)
613612

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-
625613
year = _field_accessor('year', 0, "The year of the period")
626614
month = _field_accessor('month', 3, "The month as January=1, December=12")
627615
day = _field_accessor('day', 4, "The days of the period")
@@ -1214,8 +1202,6 @@ def _make_field_arrays(*fields):
12141202

12151203
def pnow(freq=None):
12161204
# deprecation, xref #13790
1217-
import warnings
1218-
12191205
warnings.warn("pd.pnow() and pandas.core.indexes.period.pnow() "
12201206
"are deprecated. Please use Period.now()",
12211207
FutureWarning, stacklevel=2)

pandas/tests/indexes/datetimes/test_tools.py

+1-26
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
from pandas.util import testing as tm
2424
from pandas.util.testing import assert_series_equal, _skip_if_has_locale
2525
from pandas import (isna, to_datetime, Timestamp, Series, DataFrame,
26-
Index, DatetimeIndex, NaT, date_range, bdate_range,
27-
compat)
26+
Index, DatetimeIndex, NaT, date_range, compat)
2827

2928

3029
class TestTimeConversionFormats(object):
@@ -735,24 +734,6 @@ def test_dataframe_dtypes(self, cache):
735734

736735
class TestToDatetimeMisc(object):
737736

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-
756737
@pytest.mark.parametrize('cache', [True, False])
757738
def test_to_datetime_iso8601(self, cache):
758739
result = to_datetime(["2012-01-01 00:00:00"], cache=cache)
@@ -888,12 +869,6 @@ def test_to_datetime_list_of_integers(self):
888869

889870
tm.assert_index_equal(rng, result)
890871

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-
897872
def test_to_datetime_overflow(self):
898873
# gh-17637
899874
# 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)