Skip to content

Commit 1dc93b5

Browse files
chris-b1jreback
authored andcommitted
DOC: infer_objects doc fixup (#17018)
1 parent aead041 commit 1dc93b5

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

doc/source/basics.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -2025,19 +2025,20 @@ object conversion
20252025

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

20312031
.. ipython:: python
20322032
2033+
import datetime
20332034
df = pd.DataFrame([[1, 2],
20342035
['a', 'b'],
20352036
[datetime.datetime(2016, 3, 2), datetime.datetime(2016, 3, 2)]])
20362037
df = df.T
20372038
df
20382039
df.dtypes
20392040
2040-
Because the data transposed the original inference stored all columns as object, which
2041+
Because the data was transposed the original inference stored all columns as object, which
20412042
``infer_objects`` will correct.
20422043

20432044
.. ipython:: python

doc/source/whatsnew/v0.21.0.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ New features
3131
``infer_objects`` type conversion
3232
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3333

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

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

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

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

5657
df = df.infer_objects()

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3693,7 +3693,7 @@ def infer_objects(self):
36933693
columns unchanged. The inference rules are the
36943694
same as during normal Series/DataFrame construction.
36953695
3696-
.. versionadded:: 0.20.0
3696+
.. versionadded:: 0.21.0
36973697
36983698
See Also
36993699
--------

0 commit comments

Comments
 (0)