Repository: pandas-dev/pandas

Issue:
convert_object not converting to NaN
docstring seem to suggest that this ought to convert to NaN:

```
In [10]: s = pd.Series([1, 'na', 3 ,4])

In [11]: s.convert_objects(convert_numeric=True)
Out[11]:
0     1
1    na
2     3
3     4
dtype: object
```

Docstring:

```
convert_numeric : boolean, default True
    if True attempt to coerce to numbers (including strings),
    non-convertibles get NaN
```

However, does work if the non-strings are stringified first

```
In [142]: pd.Series([1, 'na', 3 ,4]).astype(str).convert_objects(convert_numeric=True)
Out[142]: 
0     1
1   NaN
2     3
3     4
dtype: float64
```



Discussion:

Resolving patch:
diff --git a/pandas/core/series.py b/pandas/core/series.py
--- a/pandas/core/series.py
+++ b/pandas/core/series.py
@@ -928,7 +928,7 @@ def astype(self, dtype):
         return self._constructor(values, index=self.index, name=self.name,
                                  dtype=values.dtype)
 
-    def convert_objects(self, convert_dates=True, convert_numeric=True, copy=True):
+    def convert_objects(self, convert_dates=True, convert_numeric=False, copy=True):
         """
         Attempt to infer better dtype
 


Test patch:
diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py
--- a/pandas/tests/test_frame.py
+++ b/pandas/tests/test_frame.py
@@ -5476,6 +5476,12 @@ def test_convert_objects(self):
         converted = self.mixed_frame.copy()
         self.assertRaises(Exception, converted['H'].astype, 'int32')
 
+        # mixed in a single column
+        df = DataFrame(dict(s = Series([1, 'na', 3 ,4])))
+        result = df.convert_objects(convert_numeric=True)
+        expected = DataFrame(dict(s = Series([1, np.nan, 3 ,4])))
+        assert_frame_equal(result, expected)
+
     def test_convert_objects_no_conversion(self):
         mixed1 = DataFrame(
             {'a': [1, 2, 3], 'b': [4.0, 5, 6], 'c': ['x', 'y', 'z']})
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
@@ -3430,25 +3430,36 @@ def test_convert_objects(self):
 
         s = Series([1., 2, 3],index=['a','b','c'])
         result = s.convert_objects(convert_dates=False,convert_numeric=True)
-        assert_series_equal(s,result)
+        assert_series_equal(result, s)
 
         # force numeric conversion
         r = s.copy().astype('O')
         r['a'] = '1'
         result = r.convert_objects(convert_dates=False,convert_numeric=True)
-        assert_series_equal(s,result)
+        assert_series_equal(result, s)
 
         r = s.copy().astype('O')
         r['a'] = '1.'
         result = r.convert_objects(convert_dates=False,convert_numeric=True)
-        assert_series_equal(s,result)
+        assert_series_equal(result, s)
 
         r = s.copy().astype('O')
         r['a'] = 'garbled'
         expected = s.copy()
         expected['a'] = np.nan
         result = r.convert_objects(convert_dates=False,convert_numeric=True)
-        assert_series_equal(expected,result)
+        assert_series_equal(result, expected)
+
+        # GH 4119, not converting a mixed type (e.g.floats and object)
+        s = Series([1, 'na', 3 ,4])
+        result = s.convert_objects(convert_numeric=True)
+        expected = Series([1,np.nan,3,4])
+        assert_series_equal(result, expected)
+
+        s = Series([1, '', 3 ,4])
+        result = s.convert_objects(convert_numeric=True)
+        expected = Series([1,np.nan,3,4])
+        assert_series_equal(result, expected)
 
         # dates
         s = Series([datetime(2001,1,1,0,0), datetime(2001,1,2,0,0), datetime(2001,1,3,0,0) ])
@@ -3456,18 +3467,17 @@ def test_convert_objects(self):
 
         result = s.convert_objects(convert_dates=True,convert_numeric=False)
         expected = Series([Timestamp('20010101'),Timestamp('20010102'),Timestamp('20010103')],dtype='M8[ns]')
-        assert_series_equal(expected,result)
+        assert_series_equal(result, expected)
 
         result = s.convert_objects(convert_dates='coerce',convert_numeric=False)
-        assert_series_equal(expected,result)
         result = s.convert_objects(convert_dates='coerce',convert_numeric=True)
-        assert_series_equal(expected,result)
+        assert_series_equal(result, expected)
 
         expected = Series([Timestamp('20010101'),Timestamp('20010102'),Timestamp('20010103'),lib.NaT,lib.NaT,lib.NaT,Timestamp('20010104'),Timestamp('20010105')],dtype='M8[ns]')
         result = s2.convert_objects(convert_dates='coerce',convert_numeric=False)
-        assert_series_equal(expected,result)
+        assert_series_equal(result, expected)
         result = s2.convert_objects(convert_dates='coerce',convert_numeric=True)
-        assert_series_equal(expected,result)
+        assert_series_equal(result, expected)
 
         # preserver all-nans (if convert_dates='coerce')
         s = Series(['foo','bar',1,1.0],dtype='O')