Skip to content

API: add infer_objects for soft conversions #16915

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 4 commits into from
Jul 18, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixups
  • Loading branch information
chris-b1 committed Jul 18, 2017
commit b5442d3b6e2340a7663d0d986ec0d8fa78b9fd1b
4 changes: 2 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3649,9 +3649,9 @@ def convert_objects(self, convert_dates=True, convert_numeric=False,

def infer_objects(self):
"""
Attempt to infer better dtypes for object columns
Attempt to infer better dtypes for object columns.

Attempts soft conversion of object dtyped
Attempts soft conversion of object-dtyped
columns, leaving non-object and unconvertible
columns unchanged. The inference rules are the
same as during normal Series/DataFrame construction.
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/series/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,5 +283,6 @@ def test_infer_objects_series(self):
actual = (Series(np.array([1, 2, 3, None, 'a'], dtype='O'))
.infer_objects())
expected = Series([1, 2, 3, None, 'a'])

assert actual.dtype == 'object'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a comment above that block of code explaining why this is the case would be useful.

Copy link
Member

@gfyoung gfyoung Jul 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why isn't there a similar test for DataFrame (i.e. one where we actually get object) ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: add newline between "expected =" and "assert " (for readability)

tm.assert_series_equal(actual, expected)