diff --git a/pandas/core/generic.py b/pandas/core/generic.py index ba4e8b0c88358..e363ab8e68408 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3,6 +3,7 @@ import operator import weakref import gc + import numpy as np import pandas.lib as lib @@ -27,6 +28,7 @@ from pandas.util.decorators import Appender, Substitution, deprecate_kwarg from pandas.core import config + # goal is to be able to define the docs close to function, while still being # able to share _shared_docs = dict() @@ -2473,6 +2475,26 @@ def convert_objects(self, datetime=False, numeric=False, ------- converted : same as input object """ + + # Deprecation code to handle usage change + issue_warning = False + if datetime == 'coerce': + datetime = coerce = True + numeric = timedelta = False + issue_warning = True + elif numeric == 'coerce': + numeric = coerce = True + datetime = timedelta = False + issue_warning = True + elif timedelta == 'coerce': + timedelta = coerce = True + datetime = numeric = False + issue_warning = True + if issue_warning: + warnings.warn("The use of 'coerce' as an input is deprecated. " + "Instead set coerce=True.", + FutureWarning) + return self._constructor( self._data.convert(datetime=datetime, numeric=numeric, diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index 6f128b2e4ff4d..58a5bf4a39000 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -6209,6 +6209,34 @@ def test_convert_objects(self): result = s.convert_objects(datetime=True, coerce=True) assert_series_equal(result, expected) + # GH 10601 + # Remove test after deprecation to convert_objects is final + def test_convert_objects_old_style_deprecation(self): + s = Series(['foo', 'bar', 1, 1.0], dtype='O') + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always', FutureWarning) + new_style = s.convert_objects(datetime=True, coerce=True) + old_style = s.convert_objects(convert_dates='coerce') + self.assertEqual(len(w), 2) + assert_series_equal(new_style, old_style) + + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always', FutureWarning) + new_style = s.convert_objects(numeric=True, coerce=True) + old_style = s.convert_objects(convert_numeric='coerce') + self.assertEqual(len(w), 2) + assert_series_equal(new_style, old_style) + + dt = datetime(2001, 1, 1, 0, 0) + td = dt - datetime(2000, 1, 1, 0, 0) + s = Series(['a', '3.1415', dt, td]) + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always', FutureWarning) + new_style = s.convert_objects(timedelta=True, coerce=True) + old_style = s.convert_objects(convert_timedeltas='coerce') + self.assertEqual(len(w), 2) + assert_series_equal(new_style, old_style) + def test_convert_objects_no_arg_warning(self): s = Series(['1.0','2']) with warnings.catch_warnings(record=True) as w: