Skip to content

CLN: Removed coerce param in pd.to_timedelta and pd.to_datetime #13602

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

Closed
Closed
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Deprecations
Removal of prior version deprecations/changes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- ``pd.to_datetime`` and ``pd.to_timedelta`` have dropped the ``coerce`` parameter in favor of ``errors`` (:issue:`13602`)



Expand Down
16 changes: 0 additions & 16 deletions pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -5514,22 +5514,6 @@ def test_second(self):


class TestDaysInMonth(tm.TestCase):
def test_coerce_deprecation(self):

# deprecation of coerce
with tm.assert_produces_warning(FutureWarning):
to_datetime('2015-02-29', coerce=True)
with tm.assert_produces_warning(FutureWarning):
self.assertRaises(ValueError,
lambda: to_datetime('2015-02-29', coerce=False))

# multiple arguments
for e, c in zip(['raise', 'ignore', 'coerce'], [True, False]):
with tm.assert_produces_warning(FutureWarning):
self.assertRaises(TypeError,
lambda: to_datetime('2015-02-29', errors=e,
coerce=c))

# tests for issue #10154
def test_day_not_in_month_coerce(self):
self.assertTrue(isnull(to_datetime('2015-02-29', errors='coerce')))
Expand Down
5 changes: 1 addition & 4 deletions pandas/tseries/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
is_timedelta64_dtype,
is_list_like)
from pandas.types.generic import ABCSeries, ABCIndexClass
from pandas.util.decorators import deprecate_kwarg


@deprecate_kwarg(old_arg_name='coerce', new_arg_name='errors',
mapping={True: 'coerce', False: 'raise'})
def to_timedelta(arg, unit='ns', box=True, errors='raise', coerce=None):
def to_timedelta(arg, unit='ns', box=True, errors='raise'):
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm no tests to remove?

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems not. That's on you! 😄

"""
Convert argument to timedelta
Expand Down
5 changes: 1 addition & 4 deletions pandas/tseries/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from pandas.types.missing import notnull

import pandas.compat as compat
from pandas.util.decorators import deprecate_kwarg

_DATEUTIL_LEXER_SPLIT = None
try:
Expand Down Expand Up @@ -175,10 +174,8 @@ def _guess_datetime_format_for_array(arr, **kwargs):
return _guess_datetime_format(arr[non_nan_elements[0]], **kwargs)


@deprecate_kwarg(old_arg_name='coerce', new_arg_name='errors',
mapping={True: 'coerce', False: 'raise'})
def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
utc=None, box=True, format=None, exact=True, coerce=None,
utc=None, box=True, format=None, exact=True,
unit=None, infer_datetime_format=False):
"""
Convert argument to datetime.
Expand Down