From 65383992a27c8b33d1badcbf7b24af3c65654465 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Sun, 21 Sep 2025 16:35:05 +0200 Subject: [PATCH] DOC: add select_dtypes case to 3.0 string migration guide --- doc/source/user_guide/migration-3-strings.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/source/user_guide/migration-3-strings.rst b/doc/source/user_guide/migration-3-strings.rst index b64fbf2a1ca46..d3c7a800b3152 100644 --- a/doc/source/user_guide/migration-3-strings.rst +++ b/doc/source/user_guide/migration-3-strings.rst @@ -195,6 +195,18 @@ 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. +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. +As an alternative, you can select both ``object`` (for pandas 2.x) and +``"string"`` (for pandas 3.x; which will also select the default ``str`` dtype +and does not error on pandas 2.x): + +.. code-block:: python + + # can use ``include=["str"]`` for pandas >= 3 + >>> df.select_dtypes(include=["object", "string"]) + The missing value sentinel is now always NaN ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~