Skip to content

CLN: Remove .to_datetime methods #18648

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

Merged
merged 1 commit into from
Dec 6, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,6 @@ Conversion
Index.map
Index.ravel
Index.tolist
Index.to_datetime
Index.to_native_types
Index.to_series
Index.to_frame
Expand Down Expand Up @@ -1757,7 +1756,6 @@ Conversion
.. autosummary::
:toctree: generated/

DatetimeIndex.to_datetime
DatetimeIndex.to_period
DatetimeIndex.to_perioddelta
DatetimeIndex.to_pydatetime
Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.22.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Removal of prior version deprecations/changes
- ``Categorical.from_array`` has been removed (:issue:`13854`)
- The ``freq`` parameter has been removed from the ``rolling``/``expanding``/``ewm`` methods of DataFrame
and Series (deprecated since v0.18). Instead, resample before calling the methods. (:issue:18601)
- ``DatetimeIndex.to_datetime``, ``Timestamp.to_datetime``, ``PeriodIndex.to_datetime``, and ``Index.to_datetime`` have been removed (:issue:`8254`, :issue:`14096`, :issue:`14113`)

.. _whatsnew_0220.performance:

Expand Down
10 changes: 0 additions & 10 deletions pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -556,16 +556,6 @@ class NaTType(_NaT):
Timestamp with fields replaced
""")

def to_datetime(self):
"""
DEPRECATED: use :meth:`to_pydatetime` instead.

Convert a Timestamp object to a native Python datetime object.
"""
warnings.warn("to_datetime is deprecated. Use self.to_pydatetime()",
FutureWarning, stacklevel=2)
return self.to_pydatetime(warn=False)


NaT = NaTType()

Expand Down
10 changes: 0 additions & 10 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,6 @@ cdef class _Timestamp(datetime):
elif other.tzinfo is None:
raise TypeError('Cannot compare tz-naive and tz-aware timestamps')

cpdef datetime to_datetime(_Timestamp self):
"""
DEPRECATED: use :meth:`to_pydatetime` instead.

Convert a Timestamp object to a native Python datetime object.
"""
warnings.warn("to_datetime is deprecated. Use self.to_pydatetime()",
FutureWarning, stacklevel=2)
return self.to_pydatetime(warn=False)

cpdef datetime to_pydatetime(_Timestamp self, warn=True):
"""
Convert a Timestamp object to a native Python datetime object.
Expand Down
20 changes: 0 additions & 20 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
algos as libalgos, join as libjoin,
Timestamp, Timedelta, )
from pandas._libs.lib import is_datetime_array
from pandas._libs.tslibs import parsing

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

def to_datetime(self, dayfirst=False):
"""
DEPRECATED: use :meth:`pandas.to_datetime` instead.

For an Index containing strings or datetime.datetime objects, attempt
conversion to DatetimeIndex
"""
warnings.warn("to_datetime is deprecated. Use pd.to_datetime(...)",
FutureWarning, stacklevel=2)

from pandas.core.indexes.datetimes import DatetimeIndex
if self.inferred_type == 'string':
from dateutil.parser import parse
parser = lambda x: parse(x, dayfirst=dayfirst)
parsed = parsing.try_parse_dates(self.values, parser=parser)
return DatetimeIndex(parsed)
else:
return DatetimeIndex(self.values)

def _assert_can_do_setop(self, other):
if not is_list_like(other):
raise TypeError('Input must be Index or array-like')
Expand Down
4 changes: 0 additions & 4 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ class DatetimeIndex(DatelikeOps, TimelikeOps, DatetimeIndexOpsMixin,
round
floor
ceil
to_datetime
to_period
to_perioddelta
to_pydatetime
Expand Down Expand Up @@ -899,9 +898,6 @@ def _format_native_types(self, na_rep='NaT', date_format=None, **kwargs):
format=format,
na_rep=na_rep)

def to_datetime(self, dayfirst=False):
return self.copy()

@Appender(_index_shared_docs['astype'])
def astype(self, dtype, copy=True):
dtype = pandas_dtype(dtype)
Expand Down
14 changes: 0 additions & 14 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import numpy as np
import warnings


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

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

def to_datetime(self, dayfirst=False):
"""
.. deprecated:: 0.19.0
Use :meth:`to_timestamp` instead.

Cast to DatetimeIndex.
"""
warnings.warn("to_datetime is deprecated. Use self.to_timestamp(...)",
FutureWarning, stacklevel=2)
return self.to_timestamp()

year = _field_accessor('year', 0, "The year of the period")
month = _field_accessor('month', 3, "The month as January=1, December=12")
day = _field_accessor('day', 4, "The days of the period")
Expand Down Expand Up @@ -1214,8 +1202,6 @@ def _make_field_arrays(*fields):

def pnow(freq=None):
# deprecation, xref #13790
import warnings

warnings.warn("pd.pnow() and pandas.core.indexes.period.pnow() "
"are deprecated. Please use Period.now()",
FutureWarning, stacklevel=2)
Expand Down
27 changes: 1 addition & 26 deletions pandas/tests/indexes/datetimes/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
from pandas.util import testing as tm
from pandas.util.testing import assert_series_equal, _skip_if_has_locale
from pandas import (isna, to_datetime, Timestamp, Series, DataFrame,
Index, DatetimeIndex, NaT, date_range, bdate_range,
compat)
Index, DatetimeIndex, NaT, date_range, compat)


class TestTimeConversionFormats(object):
Expand Down Expand Up @@ -735,24 +734,6 @@ def test_dataframe_dtypes(self, cache):

class TestToDatetimeMisc(object):

@pytest.mark.parametrize('cache', [True, False])
def test_index_to_datetime(self, cache):
idx = Index(['1/1/2000', '1/2/2000', '1/3/2000'])

with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False):
result = idx.to_datetime()
expected = DatetimeIndex(pd.to_datetime(idx.values, cache=cache))
tm.assert_index_equal(result, expected)

with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False):
today = datetime.today()
idx = Index([today], dtype=object)
result = idx.to_datetime()
expected = DatetimeIndex([today])
tm.assert_index_equal(result, expected)

@pytest.mark.parametrize('cache', [True, False])
def test_to_datetime_iso8601(self, cache):
result = to_datetime(["2012-01-01 00:00:00"], cache=cache)
Expand Down Expand Up @@ -888,12 +869,6 @@ def test_to_datetime_list_of_integers(self):

tm.assert_index_equal(rng, result)

def test_to_datetime_freq(self):
xp = bdate_range('2000-1-1', periods=10, tz='UTC')
rs = xp.to_datetime()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

odd that this didn't warn before

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed...

assert xp.freq == rs.freq
assert xp.tzinfo == rs.tzinfo

def test_to_datetime_overflow(self):
# gh-17637
# we are overflowing Timedelta range here
Expand Down
8 changes: 0 additions & 8 deletions pandas/tests/indexes/period/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,6 @@ def test_to_timestamp_1703(self):
result = index.to_timestamp()
assert result[0] == Timestamp('1/1/2012')

def test_to_datetime_depr(self):
index = period_range('1/1/2012', periods=4, freq='D')

with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False):
result = index.to_datetime()
assert result[0] == Timestamp('1/1/2012')

def test_combine_first(self):
# GH 3367
didx = pd.DatetimeIndex(start='1950-01-31', end='1950-07-31', freq='M')
Expand Down
10 changes: 0 additions & 10 deletions pandas/tests/scalar/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,16 +672,6 @@ def test_pprint(self):
'foo': 1}"""
assert result == expected

def test_to_datetime_depr(self):
# see gh-8254
ts = Timestamp('2011-01-01')

with tm.assert_produces_warning(FutureWarning,
check_stacklevel=False):
expected = datetime(2011, 1, 1)
result = ts.to_datetime()
assert result == expected

def test_to_pydatetime_nonzero_nano(self):
ts = Timestamp('2011-01-01 9:00:00.123456789')

Expand Down