Skip to content

Commit 4f332f6

Browse files
mroeschkejreback
authored andcommittedJun 2, 2019
CLN: Remove convert_objects (#26612)
1 parent 5c6dd43 commit 4f332f6

File tree

5 files changed

+2
-174
lines changed

5 files changed

+2
-174
lines changed
 

‎doc/source/reference/frame.rst

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ Conversion
4848
:toctree: api/
4949

5050
DataFrame.astype
51-
DataFrame.convert_objects
5251
DataFrame.infer_objects
5352
DataFrame.copy
5453
DataFrame.isna

‎doc/source/reference/series.rst

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ Conversion
5656

5757
Series.astype
5858
Series.infer_objects
59-
Series.convert_objects
6059
Series.copy
6160
Series.bool
6261
Series.to_numpy

‎doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ Removal of prior version deprecations/changes
483483
- Removed the previously deprecated ``TimeGrouper`` (:issue:`16942`)
484484
- Removed the previously deprecated ``parse_cols`` keyword in :func:`read_excel` (:issue:`16488`)
485485
- Removed the previously deprecated ``pd.options.html.border`` (:issue:`16970`)
486+
- Removed the previously deprecated ``convert_objects`` (:issue:`11221`)
486487

487488
.. _whatsnew_0250.performance:
488489

‎pandas/core/generic.py

+1-47
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class NDFrame(PandasObject, SelectionMixin):
113113
_internal_names_set = set(_internal_names) # type: Set[str]
114114
_accessors = set() # type: Set[str]
115115
_deprecations = frozenset([
116-
'as_blocks', 'blocks', 'convert_objects', 'is_copy'
116+
'as_blocks', 'blocks', 'is_copy'
117117
]) # type: FrozenSet[str]
118118
_metadata = [] # type: List[str]
119119
_is_copy = None
@@ -5913,52 +5913,6 @@ def _convert(self, datetime=False, numeric=False, timedelta=False,
59135913
timedelta=timedelta, coerce=coerce,
59145914
copy=copy)).__finalize__(self)
59155915

5916-
def convert_objects(self, convert_dates=True, convert_numeric=False,
5917-
convert_timedeltas=True, copy=True):
5918-
"""
5919-
Attempt to infer better dtype for object columns.
5920-
5921-
.. deprecated:: 0.21.0
5922-
5923-
Parameters
5924-
----------
5925-
convert_dates : boolean, default True
5926-
If True, convert to date where possible. If 'coerce', force
5927-
conversion, with unconvertible values becoming NaT.
5928-
convert_numeric : boolean, default False
5929-
If True, attempt to coerce to numbers (including strings), with
5930-
unconvertible values becoming NaN.
5931-
convert_timedeltas : boolean, default True
5932-
If True, convert to timedelta where possible. If 'coerce', force
5933-
conversion, with unconvertible values becoming NaT.
5934-
copy : boolean, default True
5935-
If True, return a copy even if no copy is necessary (e.g. no
5936-
conversion was done). Note: This is meant for internal use, and
5937-
should not be confused with inplace.
5938-
5939-
Returns
5940-
-------
5941-
converted : same as input object
5942-
5943-
See Also
5944-
--------
5945-
to_datetime : Convert argument to datetime.
5946-
to_timedelta : Convert argument to timedelta.
5947-
to_numeric : Convert argument to numeric type.
5948-
"""
5949-
msg = ("convert_objects is deprecated. To re-infer data dtypes for "
5950-
"object columns, use {klass}.infer_objects()\nFor all "
5951-
"other conversions use the data-type specific converters "
5952-
"pd.to_datetime, pd.to_timedelta and pd.to_numeric."
5953-
).format(klass=self.__class__.__name__)
5954-
warnings.warn(msg, FutureWarning, stacklevel=2)
5955-
5956-
return self._constructor(
5957-
self._data.convert(convert_dates=convert_dates,
5958-
convert_numeric=convert_numeric,
5959-
convert_timedeltas=convert_timedeltas,
5960-
copy=copy)).__finalize__(self)
5961-
59625916
def infer_objects(self):
59635917
"""
59645918
Attempt to infer better dtypes for object columns.

‎pandas/tests/series/test_internals.py

-125
Original file line numberDiff line numberDiff line change
@@ -12,131 +12,6 @@
1212

1313
class TestSeriesInternals:
1414

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

0 commit comments

Comments
 (0)
Please sign in to comment.