Skip to content

Commit 57dc4db

Browse files
committed
MAINT: Drop convert_objects from NDFrame
Deprecated since 0.17.0 xref gh-11173 [ci skip]
1 parent 18f929f commit 57dc4db

File tree

8 files changed

+20
-192
lines changed

8 files changed

+20
-192
lines changed

doc/source/10min.rst

+10-11
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,16 @@ will be completed:
9595
df2.append df2.combine_first
9696
df2.apply df2.compound
9797
df2.applymap df2.consolidate
98-
df2.as_blocks df2.convert_objects
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
98+
df2.as_blocks df2.copy
99+
df2.asfreq df2.corr
100+
df2.as_matrix df2.corrwith
101+
df2.astype df2.count
102+
df2.at df2.cov
103+
df2.at_time df2.cummax
104+
df2.axes df2.cumprod
105+
df2.between_time df2.cumsum
106+
df2.bfill df2.D
107+
df2.blocks
109108

110109
As you can see, the columns ``A``, ``B``, ``C``, and ``D`` are automatically
111110
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
@@ -776,7 +776,6 @@ Conversion
776776
:toctree: generated/
777777

778778
DataFrame.astype
779-
DataFrame.convert_objects
780779
DataFrame.copy
781780
DataFrame.isnull
782781
DataFrame.notnull

doc/source/whatsnew/v0.21.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ Deprecations
121121
Removal of prior version deprecations/changes
122122
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123123

124+
- ``Series``, ``Index``, and ``DataFrame`` have dropped the ``convert_objects`` method (:issue:`11173`)
124125
- :func:`read_excel()` has dropped the ``has_index_names`` parameter (:issue:`10967`)
125126
- The ``pd.options.display.mpl_style`` configuration has been dropped (:issue:`12190`)
126127
- ``Index`` has dropped the ``.sym_diff()`` method in favor of ``.symmetric_difference()`` (:issue:`12591`)

pandas/core/frame.py

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

38013801
result[col] = arr
38023802

3803-
# convert_objects just in case
3803+
# Convert objects just in case.
38043804
return self._constructor(result, index=new_index,
38053805
columns=new_columns)._convert(datetime=True,
38063806
copy=False)

pandas/core/generic.py

-45
Original file line numberDiff line numberDiff line change
@@ -3600,51 +3600,6 @@ def _convert(self, datetime=False, numeric=False, timedelta=False,
36003600
timedelta=timedelta, coerce=coerce,
36013601
copy=copy)).__finalize__(self)
36023602

3603-
# TODO: Remove in 0.18 or 2017, which ever is sooner
3604-
def convert_objects(self, convert_dates=True, convert_numeric=False,
3605-
convert_timedeltas=True, copy=True):
3606-
"""
3607-
Deprecated.
3608-
Attempt to infer better dtype for object columns
3609-
3610-
Parameters
3611-
----------
3612-
convert_dates : boolean, default True
3613-
If True, convert to date where possible. If 'coerce', force
3614-
conversion, with unconvertible values becoming NaT.
3615-
convert_numeric : boolean, default False
3616-
If True, attempt to coerce to numbers (including strings), with
3617-
unconvertible values becoming NaN.
3618-
convert_timedeltas : boolean, default True
3619-
If True, convert to timedelta where possible. If 'coerce', force
3620-
conversion, with unconvertible values becoming NaT.
3621-
copy : boolean, default True
3622-
If True, return a copy even if no copy is necessary (e.g. no
3623-
conversion was done). Note: This is meant for internal use, and
3624-
should not be confused with inplace.
3625-
3626-
See Also
3627-
--------
3628-
pandas.to_datetime : Convert argument to datetime.
3629-
pandas.to_timedelta : Convert argument to timedelta.
3630-
pandas.to_numeric : Return a fixed frequency timedelta index,
3631-
with day as the default.
3632-
3633-
Returns
3634-
-------
3635-
converted : same as input object
3636-
"""
3637-
from warnings import warn
3638-
warn("convert_objects is deprecated. Use the data-type specific "
3639-
"converters pd.to_datetime, pd.to_timedelta and pd.to_numeric.",
3640-
FutureWarning, stacklevel=2)
3641-
3642-
return self._constructor(
3643-
self._data.convert(convert_dates=convert_dates,
3644-
convert_numeric=convert_numeric,
3645-
convert_timedeltas=convert_timedeltas,
3646-
copy=copy)).__finalize__(self)
3647-
36483603
# ----------------------------------------------------------------------
36493604
# Filling NA's
36503605

pandas/core/internals.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ def _is_empty_indexer(indexer):
768768
values = self._try_coerce_and_cast_result(values, dtype)
769769
block = self.make_block(transf(values), fastpath=True)
770770

771-
# may have to soft convert_objects here
771+
# May have to soft convert objects here
772772
if block.is_object and not self.is_object:
773773
block = block.convert(numeric=False)
774774

@@ -1850,12 +1850,13 @@ def is_bool(self):
18501850
"""
18511851
return lib.is_bool_array(self.values.ravel())
18521852

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

18611862
if args:

pandas/tests/groupby/test_whitelist.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,8 @@ def test_groupby_blacklist(df_letters):
206206
s = df_letters.floats
207207

208208
blacklist = [
209-
'eval', 'query', 'abs', 'where',
210-
'mask', 'align', 'groupby', 'clip', 'astype',
211-
'at', 'combine', 'consolidate', 'convert_objects',
212-
]
209+
'eval', 'query', 'abs', 'where', 'mask', 'align',
210+
'groupby', 'clip', 'astype', 'at', 'combine', 'consolidate']
213211
to_methods = [method for method in dir(df) if method.startswith('to_')]
214212

215213
blacklist.extend(to_methods)

pandas/tests/series/test_internals.py

-125
Original file line numberDiff line numberDiff line change
@@ -18,131 +18,6 @@
1818

1919
class TestSeriesInternals(object):
2020

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

0 commit comments

Comments
 (0)