Skip to content

BUG: Fix issue with old-style usage in convert_objects #10602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import operator
import weakref
import gc

import numpy as np
import pandas.lib as lib

Expand All @@ -27,6 +28,7 @@
from pandas.util.decorators import Appender, Substitution, deprecate_kwarg
from pandas.core import config


# goal is to be able to define the docs close to function, while still being
# able to share
_shared_docs = dict()
Expand Down Expand Up @@ -2473,6 +2475,26 @@ def convert_objects(self, datetime=False, numeric=False,
-------
converted : same as input object
"""

# Deprecation code to handle usage change
issue_warning = False
if datetime == 'coerce':
datetime = coerce = True
numeric = timedelta = False
issue_warning = True
elif numeric == 'coerce':
numeric = coerce = True
datetime = timedelta = False
issue_warning = True
elif timedelta == 'coerce':
timedelta = coerce = True
datetime = numeric = False
issue_warning = True
if issue_warning:
warnings.warn("The use of 'coerce' as an input is deprecated. "
"Instead set coerce=True.",
FutureWarning)

return self._constructor(
self._data.convert(datetime=datetime,
numeric=numeric,
Expand Down
28 changes: 28 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -6209,6 +6209,34 @@ def test_convert_objects(self):
result = s.convert_objects(datetime=True, coerce=True)
assert_series_equal(result, expected)

# GH 10601
# Remove test after deprecation to convert_objects is final
def test_convert_objects_old_style_deprecation(self):
s = Series(['foo', 'bar', 1, 1.0], dtype='O')
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always', FutureWarning)
new_style = s.convert_objects(datetime=True, coerce=True)
old_style = s.convert_objects(convert_dates='coerce')
self.assertEqual(len(w), 2)
assert_series_equal(new_style, old_style)

with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always', FutureWarning)
new_style = s.convert_objects(numeric=True, coerce=True)
old_style = s.convert_objects(convert_numeric='coerce')
self.assertEqual(len(w), 2)
assert_series_equal(new_style, old_style)

dt = datetime(2001, 1, 1, 0, 0)
td = dt - datetime(2000, 1, 1, 0, 0)
s = Series(['a', '3.1415', dt, td])
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always', FutureWarning)
new_style = s.convert_objects(timedelta=True, coerce=True)
old_style = s.convert_objects(convert_timedeltas='coerce')
self.assertEqual(len(w), 2)
assert_series_equal(new_style, old_style)

def test_convert_objects_no_arg_warning(self):
s = Series(['1.0','2'])
with warnings.catch_warnings(record=True) as w:
Expand Down