Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion doc/source/user_guide/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2380,7 +2380,10 @@ To select string columns include ``str``:
.. note::

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.
This is a change in pandas 3.0. Previously strings were stored in ``object``
dtype columns, so would be selected with ``include=[object]``. See
:ref:`the migration guide <string_migration.select_dtypes>` for details on
how to write code that works with both versions.

To see all the child dtypes of a generic ``dtype`` like ``numpy.number`` you
can define a function that returns a tree of child dtypes:
Expand Down
2 changes: 2 additions & 0 deletions doc/source/user_guide/migration-3-strings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ This is actually compatible with pandas 2.x as well, since in pandas < 3,
of also stringifying missing values in pandas 2.x. See the section
:ref:`string_migration_guide-astype_str` for more details.

.. _string_migration.select_dtypes:

For selecting string columns with :meth:`~DataFrame.select_dtypes` in a pandas
2.x and 3.x compatible way, it is not possible to use ``"str"``. While this
works for pandas 3.x, it raises an error in pandas 2.x.
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5253,7 +5253,10 @@ def predicate(arr: ArrayLike) -> bool:
"select_dtypes when 'object' dtype is specified. "
"This behavior is deprecated and will be removed in a future "
"version. Explicitly pass 'str' to `include` to select them, "
"or to `exclude` to remove them and silence this warning.",
"or to `exclude` to remove them and silence this warning.\nSee "
"https://pandas.pydata.org/docs/user_guide/migration-3-strings.html"
"#string-migration-select-dtypes for details on how to write code "
"that works with pandas 2 and 3.",
Pandas4Warning,
stacklevel=find_stack_level(),
)
Expand Down
Loading