Skip to content

Commit 2bb3fef

Browse files
DOC: add reference to select_dtypes section in string migration guide (#62759)
1 parent 15ca85b commit 2bb3fef

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

doc/source/user_guide/basics.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2380,7 +2380,10 @@ To select string columns include ``str``:
23802380
23812381
.. note::
23822382

2383-
This is a change in pandas 3.0. Previously strings were stored in ``object`` dtype columns, so would be selected with ``include=[object]``. See https://pandas.pydata.org/docs/user_guide/migration-3-strings.html#hardcoded-use-of-object-dtype.
2383+
This is a change in pandas 3.0. Previously strings were stored in ``object``
2384+
dtype columns, so would be selected with ``include=[object]``. See
2385+
:ref:`the migration guide <string_migration.select_dtypes>` for details on
2386+
how to write code that works with both versions.
23842387

23852388
To see all the child dtypes of a generic ``dtype`` like ``numpy.number`` you
23862389
can define a function that returns a tree of child dtypes:

doc/source/user_guide/migration-3-strings.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ This is actually compatible with pandas 2.x as well, since in pandas < 3,
195195
of also stringifying missing values in pandas 2.x. See the section
196196
:ref:`string_migration_guide-astype_str` for more details.
197197

198+
.. _string_migration.select_dtypes:
199+
198200
For selecting string columns with :meth:`~DataFrame.select_dtypes` in a pandas
199201
2.x and 3.x compatible way, it is not possible to use ``"str"``. While this
200202
works for pandas 3.x, it raises an error in pandas 2.x.

pandas/core/frame.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5253,7 +5253,10 @@ def predicate(arr: ArrayLike) -> bool:
52535253
"select_dtypes when 'object' dtype is specified. "
52545254
"This behavior is deprecated and will be removed in a future "
52555255
"version. Explicitly pass 'str' to `include` to select them, "
5256-
"or to `exclude` to remove them and silence this warning.",
5256+
"or to `exclude` to remove them and silence this warning.\nSee "
5257+
"https://pandas.pydata.org/docs/user_guide/migration-3-strings.html"
5258+
"#string-migration-select-dtypes for details on how to write code "
5259+
"that works with pandas 2 and 3.",
52575260
Pandas4Warning,
52585261
stacklevel=find_stack_level(),
52595262
)

0 commit comments

Comments
 (0)