Repository: pandas-dev/pandas

Issue:
BUG in dealing with deprecated argument in convert_objects 
cc @bashtage

The deprecation warning is triggered, but the value of the keyword argument should also be adapted so it still works with the new code I think (from a failure in the docs)

```
In [1]: from datetime import datetime

In [2]: s = pd.Series([datetime(2001,1,1,0,0), 'foo', 1.0, 1,
   ...:                pd.Timestamp('20010104'), '20010105'], dtype='O')

In [5]: s.convert_objects(convert_dates='coerce')
c:\users\vdbosscj\scipy\pandas-joris\pandas\util\decorators.py:81: FutureWarning
: the 'convert_dates' keyword is deprecated, use 'datetime' instead
  warnings.warn(msg, FutureWarning)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-b962b638ac86> in <module>()
----> 1 s.convert_objects(convert_dates='coerce')

c:\users\vdbosscj\scipy\pandas-joris\pandas\util\decorators.pyc in wrapper(*args
, **kwargs)
     86                 else:
     87                     kwargs[new_arg_name] = new_arg_value
---> 88             return func(*args, **kwargs)
     89         return wrapper
     90     return _deprecate_kwarg

c:\users\vdbosscj\scipy\pandas-joris\pandas\util\decorators.pyc in wrapper(*args
, **kwargs)
     86                 else:
     87                     kwargs[new_arg_name] = new_arg_value
---> 88             return func(*args, **kwargs)
     89         return wrapper
     90     return _deprecate_kwarg

c:\users\vdbosscj\scipy\pandas-joris\pandas\util\decorators.pyc in wrapper(*args
, **kwargs)
     86                 else:
     87                     kwargs[new_arg_name] = new_arg_value
---> 88             return func(*args, **kwargs)
     89         return wrapper
     90     return _deprecate_kwarg

c:\users\vdbosscj\scipy\pandas-joris\pandas\core\generic.py in convert_objects(s
elf, datetime, numeric, timedelta, coerce, copy)
   2468                                timedelta=timedelta,
   2469                                coerce=coerce,
-> 2470                                copy=copy)).__finalize__(self)
   2471
   2472     #-------------------------------------------------------------------

---

c:\users\vdbosscj\scipy\pandas-joris\pandas\core\internals.py in convert(self, *
*kwargs)
   3459         """ convert the whole block as one """
   3460         kwargs['by_item'] = False
-> 3461         return self.apply('convert', **kwargs)
   3462
   3463     @property

c:\users\vdbosscj\scipy\pandas-joris\pandas\core\internals.py in apply(self, f,
axes, filter, do_integrity_check, **kwargs)
   2467                                                  copy=align_copy)
   2468
-> 2469             applied = getattr(b, f)(**kwargs)
   2470
   2471             if isinstance(applied, list):

c:\users\vdbosscj\scipy\pandas-joris\pandas\core\internals.py in convert(self, d
atetime, numeric, timedelta, coerce, copy, by_item)
   1493                 timedelta=timedelta,
   1494                 coerce=coerce,
-> 1495                 copy=copy
   1496             ).reshape(self.values.shape)
   1497             blocks.append(make_block(values,

c:\users\vdbosscj\scipy\pandas-joris\pandas\core\common.py in _possibly_convert_
objects(values, datetime, numeric, timedelta, coerce, copy)
   1897     """ if we have an object dtype, try to coerce dates and/or numbers "
""
   1898
-> 1899     conversion_count = sum((datetime, numeric, timedelta))
   1900     if conversion_count == 0:
   1901         import warnings

TypeError: unsupported operand type(s) for +: 'int' and 'str'
```



Discussion:
I agree that this requires some messy handling until the old style is killed.  


Resolving patch:
diff --git a/pandas/core/generic.py b/pandas/core/generic.py
--- 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,


Test patch:
diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py
--- 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: