diff --git a/doc/source/10min.rst b/doc/source/10min.rst index 8482eef552c17a..81d48ff3bacb42 100644 --- a/doc/source/10min.rst +++ b/doc/source/10min.rst @@ -95,17 +95,16 @@ will be completed: df2.append df2.combine_first df2.apply df2.compound df2.applymap df2.consolidate - df2.as_blocks df2.convert_objects - df2.asfreq df2.copy - df2.as_matrix df2.corr - df2.astype df2.corrwith - df2.at df2.count - df2.at_time df2.cov - df2.axes df2.cummax - df2.B df2.cummin - df2.between_time df2.cumprod - df2.bfill df2.cumsum - df2.blocks df2.D + df2.as_blocks df2.copy + df2.asfreq df2.corr + df2.as_matrix df2.corrwith + df2.astype df2.count + df2.at df2.cov + df2.at_time df2.cummax + df2.axes df2.cumprod + df2.between_time df2.cumsum + df2.bfill df2.D + df2.blocks As you can see, the columns ``A``, ``B``, ``C``, and ``D`` are automatically tab completed. ``E`` is there as well; the rest of the attributes have been diff --git a/doc/source/api.rst b/doc/source/api.rst index d6053791d6f4be..1a62cde362edef 100644 --- a/doc/source/api.rst +++ b/doc/source/api.rst @@ -776,7 +776,6 @@ Conversion :toctree: generated/ DataFrame.astype - DataFrame.convert_objects DataFrame.copy DataFrame.isnull DataFrame.notnull diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index 9d475390175b28..6aee9f91cef972 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -1535,6 +1535,7 @@ Removal of prior version deprecations/changes - ``Series``, ``Index``, and ``DataFrame`` have dropped the ``sort`` and ``order`` methods (:issue:`10726`) - Where clauses in ``pytables`` are only accepted as strings and expressions types and not other data-types (:issue:`12027`) - ``DataFrame`` has dropped the ``combineAdd`` and ``combineMult`` methods in favor of ``add`` and ``mul`` respectively (:issue:`10735`) +- ``Series``, ``Index``, and ``DataFrame`` have dropped the ``convert_objects`` method (:issue:`11173`) .. _whatsnew_0200.performance: diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 2b2e7be62427b4..4375b1cab3019b 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3803,7 +3803,7 @@ def combine(self, other, func, fill_value=None, overwrite=True): result[col] = arr - # convert_objects just in case + # Convert objects just in case. return self._constructor(result, index=new_index, columns=new_columns)._convert(datetime=True, copy=False) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index fdf5d01484b98f..3fd6b4bc17be0f 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3597,52 +3597,6 @@ def _convert(self, datetime=False, numeric=False, timedelta=False, timedelta=timedelta, coerce=coerce, copy=copy)).__finalize__(self) - # TODO: Remove in 0.18 or 2017, which ever is sooner - def convert_objects(self, convert_dates=True, convert_numeric=False, - convert_timedeltas=True, copy=True): - """ - Deprecated. - - Attempt to infer better dtype for object columns - - Parameters - ---------- - convert_dates : boolean, default True - If True, convert to date where possible. If 'coerce', force - conversion, with unconvertible values becoming NaT. - convert_numeric : boolean, default False - If True, attempt to coerce to numbers (including strings), with - unconvertible values becoming NaN. - convert_timedeltas : boolean, default True - If True, convert to timedelta where possible. If 'coerce', force - conversion, with unconvertible values becoming NaT. - copy : boolean, default True - If True, return a copy even if no copy is necessary (e.g. no - conversion was done). Note: This is meant for internal use, and - should not be confused with inplace. - - See Also - -------- - pandas.to_datetime : Convert argument to datetime. - pandas.to_timedelta : Convert argument to timedelta. - pandas.to_numeric : Return a fixed frequency timedelta index, - with day as the default. - - Returns - ------- - converted : same as input object - """ - from warnings import warn - warn("convert_objects is deprecated. Use the data-type specific " - "converters pd.to_datetime, pd.to_timedelta and pd.to_numeric.", - FutureWarning, stacklevel=2) - - return self._constructor( - self._data.convert(convert_dates=convert_dates, - convert_numeric=convert_numeric, - convert_timedeltas=convert_timedeltas, - copy=copy)).__finalize__(self) - # ---------------------------------------------------------------------- # Filling NA's diff --git a/pandas/core/internals.py b/pandas/core/internals.py index f2a7ac76481d4a..29a6276aee4bdf 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -768,7 +768,7 @@ def _is_empty_indexer(indexer): values = self._try_coerce_and_cast_result(values, dtype) block = self.make_block(transf(values), fastpath=True) - # may have to soft convert_objects here + # May have to soft convert objects here if block.is_object and not self.is_object: block = block.convert(numeric=False) @@ -1850,12 +1850,13 @@ def is_bool(self): """ return lib.is_bool_array(self.values.ravel()) - # TODO: Refactor when convert_objects is removed since there will be 1 path def convert(self, *args, **kwargs): - """ attempt to coerce any object types to better types return a copy of - the block (if copy = True) by definition we ARE an ObjectBlock!!!!! + """ + Attempt to coerce any object types to more specific data types. + If copy = True, return a copy of the block. - can return multiple blocks! + NOTE: This function can can return multiple blocks! + NOTE: By definition, we are an ObjectBlock! """ if args: diff --git a/pandas/tests/groupby/test_whitelist.py b/pandas/tests/groupby/test_whitelist.py index 2c8bf57f20faea..5a4a402b8e02d6 100644 --- a/pandas/tests/groupby/test_whitelist.py +++ b/pandas/tests/groupby/test_whitelist.py @@ -206,10 +206,8 @@ def test_groupby_blacklist(df_letters): s = df_letters.floats blacklist = [ - 'eval', 'query', 'abs', 'where', - 'mask', 'align', 'groupby', 'clip', 'astype', - 'at', 'combine', 'consolidate', 'convert_objects', - ] + 'eval', 'query', 'abs', 'where', 'mask', 'align', + 'groupby', 'clip', 'astype', 'at', 'combine', 'consolidate'] to_methods = [method for method in dir(df) if method.startswith('to_')] blacklist.extend(to_methods) diff --git a/pandas/tests/series/test_internals.py b/pandas/tests/series/test_internals.py index 79e23459ac9923..4e4754efba5fc4 100644 --- a/pandas/tests/series/test_internals.py +++ b/pandas/tests/series/test_internals.py @@ -18,131 +18,6 @@ class TestSeriesInternals(object): - def test_convert_objects(self): - - s = Series([1., 2, 3], index=['a', 'b', 'c']) - with tm.assert_produces_warning(FutureWarning): - result = s.convert_objects(convert_dates=False, - convert_numeric=True) - assert_series_equal(result, s) - - # force numeric conversion - r = s.copy().astype('O') - r['a'] = '1' - with tm.assert_produces_warning(FutureWarning): - result = r.convert_objects(convert_dates=False, - convert_numeric=True) - assert_series_equal(result, s) - - r = s.copy().astype('O') - r['a'] = '1.' - with tm.assert_produces_warning(FutureWarning): - result = r.convert_objects(convert_dates=False, - convert_numeric=True) - assert_series_equal(result, s) - - r = s.copy().astype('O') - r['a'] = 'garbled' - expected = s.copy() - expected['a'] = np.nan - with tm.assert_produces_warning(FutureWarning): - result = r.convert_objects(convert_dates=False, - convert_numeric=True) - assert_series_equal(result, expected) - - # GH 4119, not converting a mixed type (e.g.floats and object) - s = Series([1, 'na', 3, 4]) - with tm.assert_produces_warning(FutureWarning): - result = s.convert_objects(convert_numeric=True) - expected = Series([1, np.nan, 3, 4]) - assert_series_equal(result, expected) - - s = Series([1, '', 3, 4]) - with tm.assert_produces_warning(FutureWarning): - 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)]) - s2 = Series([datetime(2001, 1, 1, 0, 0), datetime(2001, 1, 2, 0, 0), - datetime(2001, 1, 3, 0, 0), 'foo', 1.0, 1, - Timestamp('20010104'), '20010105'], - dtype='O') - with tm.assert_produces_warning(FutureWarning): - result = s.convert_objects(convert_dates=True, - convert_numeric=False) - expected = Series([Timestamp('20010101'), Timestamp('20010102'), - Timestamp('20010103')], dtype='M8[ns]') - assert_series_equal(result, expected) - - with tm.assert_produces_warning(FutureWarning): - result = s.convert_objects(convert_dates='coerce', - convert_numeric=False) - with tm.assert_produces_warning(FutureWarning): - result = s.convert_objects(convert_dates='coerce', - convert_numeric=True) - 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]') - with tm.assert_produces_warning(FutureWarning): - result = s2.convert_objects(convert_dates='coerce', - convert_numeric=False) - assert_series_equal(result, expected) - with tm.assert_produces_warning(FutureWarning): - result = s2.convert_objects(convert_dates='coerce', - convert_numeric=True) - assert_series_equal(result, expected) - - # preserver all-nans (if convert_dates='coerce') - s = Series(['foo', 'bar', 1, 1.0], dtype='O') - with tm.assert_produces_warning(FutureWarning): - result = s.convert_objects(convert_dates='coerce', - convert_numeric=False) - expected = Series([lib.NaT] * 2 + [Timestamp(1)] * 2) - assert_series_equal(result, expected) - - # preserver if non-object - s = Series([1], dtype='float32') - with tm.assert_produces_warning(FutureWarning): - result = s.convert_objects(convert_dates='coerce', - convert_numeric=False) - assert_series_equal(result, s) - - # r = s.copy() - # r[0] = np.nan - # result = r.convert_objects(convert_dates=True,convert_numeric=False) - # assert result.dtype == 'M8[ns]' - - # dateutil parses some single letters into today's value as a date - for x in 'abcdefghijklmnopqrstuvwxyz': - s = Series([x]) - with tm.assert_produces_warning(FutureWarning): - result = s.convert_objects(convert_dates='coerce') - assert_series_equal(result, s) - s = Series([x.upper()]) - with tm.assert_produces_warning(FutureWarning): - result = s.convert_objects(convert_dates='coerce') - assert_series_equal(result, s) - - def test_convert_objects_preserve_bool(self): - s = Series([1, True, 3, 5], dtype=object) - with tm.assert_produces_warning(FutureWarning): - r = s.convert_objects(convert_numeric=True) - e = Series([1, 1, 3, 5], dtype='i8') - tm.assert_series_equal(r, e) - - def test_convert_objects_preserve_all_bool(self): - s = Series([False, True, False, False], dtype=object) - with tm.assert_produces_warning(FutureWarning): - r = s.convert_objects(convert_numeric=True) - e = Series([False, True, False, False], dtype=bool) - tm.assert_series_equal(r, e) - # GH 10265 def test_convert(self): # Tests: All to nans, coerce, true