Skip to content

Commit 7abb65b

Browse files
Make 'indexing may change dtype' more general
1 parent 53a6970 commit 7abb65b

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

doc/source/advanced.rst

+14-7
Original file line numberDiff line numberDiff line change
@@ -954,17 +954,24 @@ in the way that standard Python integer slicing works.
954954
Indexing potentially changes underlying Series dtype
955955
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
956956
957-
The use of ``reindex_like`` can potentially change the dtype of a ``Series``.
957+
The different indexing operation can potentially change the dtype of a ``Series``.
958958
959959
.. ipython:: python
960960
961-
series = pd.Series([1, 2, 3])
962-
x = pd.Series([True])
963-
x.dtype
964-
x = pd.Series([True]).reindex_like(series)
965-
x.dtype
961+
series1 = pd.Series([1, 2, 3])
962+
series1.dtype
963+
res = series1[[0,4]]
964+
res.dtype
965+
res
966966
967-
This is because ``reindex_like`` silently inserts ``NaNs`` and the ``dtype``
967+
.. ipython:: python
968+
series2 = pd.Series([True])
969+
series2.dtype
970+
res = series2.reindex_like(series1)
971+
res.dtype
972+
res
973+
974+
This is because the (re)indexing operations above silently inserts ``NaNs`` and the ``dtype``
968975
changes accordingly. This can cause some issues when using ``numpy`` ``ufuncs``
969976
such as ``numpy.logical_and``.
970977

0 commit comments

Comments
 (0)