Skip to content

Commit 6eb86ff

Browse files
committed
MAINT: Drop convert_objects from NDFrame
Deprecated since 0.17.0 xref gh-11173
1 parent aa9d0cf commit 6eb86ff

File tree

8 files changed

+21
-191
lines changed

8 files changed

+21
-191
lines changed

doc/source/10min.rst

+11-11
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,17 @@ will be completed:
9696
df2.apply df2.combineMult
9797
df2.applymap df2.compound
9898
df2.as_blocks df2.consolidate
99-
df2.asfreq df2.convert_objects
100-
df2.as_matrix df2.copy
101-
df2.astype df2.corr
102-
df2.at df2.corrwith
103-
df2.at_time df2.count
104-
df2.axes df2.cov
105-
df2.B df2.cummax
106-
df2.between_time df2.cummin
107-
df2.bfill df2.cumprod
108-
df2.blocks df2.cumsum
109-
df2.bool df2.D
99+
df2.asfreq df2.copy
100+
df2.as_matrix df2.corr
101+
df2.astype df2.corrwith
102+
df2.at df2.count
103+
df2.at_time df2.cov
104+
df2.axes df2.cummax
105+
df2.B df2.cummin
106+
df2.between_time df2.cumprod
107+
df2.bfill df2.cumsum
108+
df2.blocks df2.D
109+
df2.bool
110110

111111
As you can see, the columns ``A``, ``B``, ``C``, and ``D`` are automatically
112112
tab completed. ``E`` is there as well; the rest of the attributes have been

doc/source/api.rst

-1
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,6 @@ Conversion
760760
:toctree: generated/
761761

762762
DataFrame.astype
763-
DataFrame.convert_objects
764763
DataFrame.copy
765764
DataFrame.isnull
766765
DataFrame.notnull

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ Removal of prior version deprecations/changes
773773
- The ``take_last`` parameter has been dropped from ``duplicated()``, ``drop_duplicates()``, ``nlargest()``, and ``nsmallest()`` methods (:issue:`10236`, :issue:`10792`, :issue:`10920`)
774774
- ``Series``, ``Index``, and ``DataFrame`` have dropped the ``sort`` and ``order`` methods (:issue:`10726`)
775775
- The ``LongPanel`` and ``WidePanel`` classes have been removed (:issue:`10892`)
776+
- ``Series``, ``Index``, and ``DataFrame`` have dropped the ``convert_objects`` method (:issue:`11173`)
776777

777778
.. _whatsnew_0200.performance:
778779

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3753,7 +3753,7 @@ def combine(self, other, func, fill_value=None, overwrite=True):
37533753

37543754
result[col] = arr
37553755

3756-
# convert_objects just in case
3756+
# Convert objects just in case.
37573757
return self._constructor(result, index=new_index,
37583758
columns=new_columns)._convert(datetime=True,
37593759
copy=False)

pandas/core/generic.py

-46
Original file line numberDiff line numberDiff line change
@@ -3280,52 +3280,6 @@ def _convert(self, datetime=False, numeric=False, timedelta=False,
32803280
timedelta=timedelta, coerce=coerce,
32813281
copy=copy)).__finalize__(self)
32823282

3283-
# TODO: Remove in 0.18 or 2017, which ever is sooner
3284-
def convert_objects(self, convert_dates=True, convert_numeric=False,
3285-
convert_timedeltas=True, copy=True):
3286-
"""
3287-
Deprecated.
3288-
3289-
Attempt to infer better dtype for object columns
3290-
3291-
Parameters
3292-
----------
3293-
convert_dates : boolean, default True
3294-
If True, convert to date where possible. If 'coerce', force
3295-
conversion, with unconvertible values becoming NaT.
3296-
convert_numeric : boolean, default False
3297-
If True, attempt to coerce to numbers (including strings), with
3298-
unconvertible values becoming NaN.
3299-
convert_timedeltas : boolean, default True
3300-
If True, convert to timedelta where possible. If 'coerce', force
3301-
conversion, with unconvertible values becoming NaT.
3302-
copy : boolean, default True
3303-
If True, return a copy even if no copy is necessary (e.g. no
3304-
conversion was done). Note: This is meant for internal use, and
3305-
should not be confused with inplace.
3306-
3307-
See Also
3308-
--------
3309-
pandas.to_datetime : Convert argument to datetime.
3310-
pandas.to_timedelta : Convert argument to timedelta.
3311-
pandas.to_numeric : Return a fixed frequency timedelta index,
3312-
with day as the default.
3313-
3314-
Returns
3315-
-------
3316-
converted : same as input object
3317-
"""
3318-
from warnings import warn
3319-
warn("convert_objects is deprecated. Use the data-type specific "
3320-
"converters pd.to_datetime, pd.to_timedelta and pd.to_numeric.",
3321-
FutureWarning, stacklevel=2)
3322-
3323-
return self._constructor(
3324-
self._data.convert(convert_dates=convert_dates,
3325-
convert_numeric=convert_numeric,
3326-
convert_timedeltas=convert_timedeltas,
3327-
copy=copy)).__finalize__(self)
3328-
33293283
# ----------------------------------------------------------------------
33303284
# Filling NA's
33313285

pandas/core/internals.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ def _is_empty_indexer(indexer):
764764
values = self._try_coerce_and_cast_result(values, dtype)
765765
block = self.make_block(transf(values), fastpath=True)
766766

767-
# may have to soft convert_objects here
767+
# May have to soft convert objects here
768768
if block.is_object and not self.is_object:
769769
block = block.convert(numeric=False)
770770

@@ -1846,12 +1846,13 @@ def is_bool(self):
18461846
"""
18471847
return lib.is_bool_array(self.values.ravel())
18481848

1849-
# TODO: Refactor when convert_objects is removed since there will be 1 path
18501849
def convert(self, *args, **kwargs):
1851-
""" attempt to coerce any object types to better types return a copy of
1852-
the block (if copy = True) by definition we ARE an ObjectBlock!!!!!
1850+
"""
1851+
Attempt to coerce any object types to more specific data types.
1852+
If copy = True, return a copy of the block.
18531853
1854-
can return multiple blocks!
1854+
NOTE: This function can can return multiple blocks!
1855+
NOTE: By definition, we are an ObjectBlock!
18551856
"""
18561857

18571858
if args:

pandas/tests/groupby/test_groupby.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3876,8 +3876,8 @@ def test_groupby_blacklist(self):
38763876

38773877
blacklist = [
38783878
'eval', 'query', 'abs', 'where',
3879-
'mask', 'align', 'groupby', 'clip', 'astype',
3880-
'at', 'combine', 'consolidate', 'convert_objects',
3879+
'mask', 'align', 'groupby', 'clip',
3880+
'astype', 'at', 'combine', 'consolidate',
38813881
]
38823882
to_methods = [method for method in dir(df) if method.startswith('to_')]
38833883

pandas/tests/series/test_internals.py

-125
Original file line numberDiff line numberDiff line change
@@ -16,131 +16,6 @@
1616

1717
class TestSeriesInternals(tm.TestCase):
1818

19-
def test_convert_objects(self):
20-
21-
s = Series([1., 2, 3], index=['a', 'b', 'c'])
22-
with tm.assert_produces_warning(FutureWarning):
23-
result = s.convert_objects(convert_dates=False,
24-
convert_numeric=True)
25-
assert_series_equal(result, s)
26-
27-
# force numeric conversion
28-
r = s.copy().astype('O')
29-
r['a'] = '1'
30-
with tm.assert_produces_warning(FutureWarning):
31-
result = r.convert_objects(convert_dates=False,
32-
convert_numeric=True)
33-
assert_series_equal(result, s)
34-
35-
r = s.copy().astype('O')
36-
r['a'] = '1.'
37-
with tm.assert_produces_warning(FutureWarning):
38-
result = r.convert_objects(convert_dates=False,
39-
convert_numeric=True)
40-
assert_series_equal(result, s)
41-
42-
r = s.copy().astype('O')
43-
r['a'] = 'garbled'
44-
expected = s.copy()
45-
expected['a'] = np.nan
46-
with tm.assert_produces_warning(FutureWarning):
47-
result = r.convert_objects(convert_dates=False,
48-
convert_numeric=True)
49-
assert_series_equal(result, expected)
50-
51-
# GH 4119, not converting a mixed type (e.g.floats and object)
52-
s = Series([1, 'na', 3, 4])
53-
with tm.assert_produces_warning(FutureWarning):
54-
result = s.convert_objects(convert_numeric=True)
55-
expected = Series([1, np.nan, 3, 4])
56-
assert_series_equal(result, expected)
57-
58-
s = Series([1, '', 3, 4])
59-
with tm.assert_produces_warning(FutureWarning):
60-
result = s.convert_objects(convert_numeric=True)
61-
expected = Series([1, np.nan, 3, 4])
62-
assert_series_equal(result, expected)
63-
64-
# dates
65-
s = Series([datetime(2001, 1, 1, 0, 0), datetime(2001, 1, 2, 0, 0),
66-
datetime(2001, 1, 3, 0, 0)])
67-
s2 = Series([datetime(2001, 1, 1, 0, 0), datetime(2001, 1, 2, 0, 0),
68-
datetime(2001, 1, 3, 0, 0), 'foo', 1.0, 1,
69-
Timestamp('20010104'), '20010105'],
70-
dtype='O')
71-
with tm.assert_produces_warning(FutureWarning):
72-
result = s.convert_objects(convert_dates=True,
73-
convert_numeric=False)
74-
expected = Series([Timestamp('20010101'), Timestamp('20010102'),
75-
Timestamp('20010103')], dtype='M8[ns]')
76-
assert_series_equal(result, expected)
77-
78-
with tm.assert_produces_warning(FutureWarning):
79-
result = s.convert_objects(convert_dates='coerce',
80-
convert_numeric=False)
81-
with tm.assert_produces_warning(FutureWarning):
82-
result = s.convert_objects(convert_dates='coerce',
83-
convert_numeric=True)
84-
assert_series_equal(result, expected)
85-
86-
expected = Series([Timestamp('20010101'), Timestamp('20010102'),
87-
Timestamp('20010103'),
88-
lib.NaT, lib.NaT, lib.NaT, Timestamp('20010104'),
89-
Timestamp('20010105')], dtype='M8[ns]')
90-
with tm.assert_produces_warning(FutureWarning):
91-
result = s2.convert_objects(convert_dates='coerce',
92-
convert_numeric=False)
93-
assert_series_equal(result, expected)
94-
with tm.assert_produces_warning(FutureWarning):
95-
result = s2.convert_objects(convert_dates='coerce',
96-
convert_numeric=True)
97-
assert_series_equal(result, expected)
98-
99-
# preserver all-nans (if convert_dates='coerce')
100-
s = Series(['foo', 'bar', 1, 1.0], dtype='O')
101-
with tm.assert_produces_warning(FutureWarning):
102-
result = s.convert_objects(convert_dates='coerce',
103-
convert_numeric=False)
104-
expected = Series([lib.NaT] * 2 + [Timestamp(1)] * 2)
105-
assert_series_equal(result, expected)
106-
107-
# preserver if non-object
108-
s = Series([1], dtype='float32')
109-
with tm.assert_produces_warning(FutureWarning):
110-
result = s.convert_objects(convert_dates='coerce',
111-
convert_numeric=False)
112-
assert_series_equal(result, s)
113-
114-
# r = s.copy()
115-
# r[0] = np.nan
116-
# result = r.convert_objects(convert_dates=True,convert_numeric=False)
117-
# self.assertEqual(result.dtype, 'M8[ns]')
118-
119-
# dateutil parses some single letters into today's value as a date
120-
for x in 'abcdefghijklmnopqrstuvwxyz':
121-
s = Series([x])
122-
with tm.assert_produces_warning(FutureWarning):
123-
result = s.convert_objects(convert_dates='coerce')
124-
assert_series_equal(result, s)
125-
s = Series([x.upper()])
126-
with tm.assert_produces_warning(FutureWarning):
127-
result = s.convert_objects(convert_dates='coerce')
128-
assert_series_equal(result, s)
129-
130-
def test_convert_objects_preserve_bool(self):
131-
s = Series([1, True, 3, 5], dtype=object)
132-
with tm.assert_produces_warning(FutureWarning):
133-
r = s.convert_objects(convert_numeric=True)
134-
e = Series([1, 1, 3, 5], dtype='i8')
135-
tm.assert_series_equal(r, e)
136-
137-
def test_convert_objects_preserve_all_bool(self):
138-
s = Series([False, True, False, False], dtype=object)
139-
with tm.assert_produces_warning(FutureWarning):
140-
r = s.convert_objects(convert_numeric=True)
141-
e = Series([False, True, False, False], dtype=bool)
142-
tm.assert_series_equal(r, e)
143-
14419
# GH 10265
14520
def test_convert(self):
14621
# Tests: All to nans, coerce, true

0 commit comments

Comments
 (0)