Skip to content

Commit

Permalink
DOC: infer_objects doc fixup (#17018)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-b1 authored and jreback committed Jul 19, 2017
1 parent aead041 commit 1dc93b5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions doc/source/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2025,19 +2025,20 @@ object conversion

pandas offers various functions to try to force conversion of types from the ``object`` dtype to other types.
In cases where the data is already of the correct type, but stored in an ``object`` array, the
:meth:`~DataFrame.infer_objects` and :meth:`~Series.infer_objects` can be used to soft convert
:meth:`DataFrame.infer_objects` and :meth:`Series.infer_objects` methods can be used to soft convert
to the correct type.

.. ipython:: python
import datetime
df = pd.DataFrame([[1, 2],
['a', 'b'],
[datetime.datetime(2016, 3, 2), datetime.datetime(2016, 3, 2)]])
df = df.T
df
df.dtypes
Because the data transposed the original inference stored all columns as object, which
Because the data was transposed the original inference stored all columns as object, which
``infer_objects`` will correct.

.. ipython:: python
Expand Down
9 changes: 5 additions & 4 deletions doc/source/whatsnew/v0.21.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ New features
``infer_objects`` type conversion
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The `:meth:`~DataFrame.infer_objects` and :meth:`~Series.infer_objects`
The :meth:`DataFrame.infer_objects` and :meth:`Series.infer_objects`
methods have been added to perform dtype inference on object columns, replacing
some of the functionality of the deprecated ``convert_objects``
method. See the documentation :ref:`here <basics.object_conversion>`
for more details. (:issue:`11221`)

This function only performs soft conversions on object columns, converting Python objects
This method only performs soft conversions on object columns, converting Python objects
to native types, but not any coercive conversions. For example:

.. ipython:: python
Expand All @@ -46,11 +46,12 @@ to native types, but not any coercive conversions. For example:
'B': np.array([1, 2, 3], dtype='object'),
'C': ['1', '2', '3']})
df.dtypes
df.infer_objects().dtype
df.infer_objects().dtypes

Note that column ``'C'`` was not converted - only scalar numeric types
will be inferred to a new type. Other types of conversion should be accomplished
using :func:`to_numeric` function (or :func:`to_datetime`, :func:`to_timedelta`).
using the :func:`to_numeric` function (or :func:`to_datetime`, :func:`to_timedelta`).

.. ipython:: python

df = df.infer_objects()
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3693,7 +3693,7 @@ def infer_objects(self):
columns unchanged. The inference rules are the
same as during normal Series/DataFrame construction.
.. versionadded:: 0.20.0
.. versionadded:: 0.21.0
See Also
--------
Expand Down

0 comments on commit 1dc93b5

Please sign in to comment.