Skip to content

Commit 0601990

Browse files
jorisvandenbosschemeeseeksmachine
authored andcommitted
Backport PR pandas-dev#62403: DOC: add select_dtypes case to 3.0 string migration guide
1 parent fd2f7eb commit 0601990

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,18 @@ 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+
For selecting string columns with :meth:`~DataFrame.select_dtypes` in a pandas
199+
2.x and 3.x compatible way, it is not possible to use ``"str"``. While this
200+
works for pandas 3.x, it raises an error in pandas 2.x.
201+
As an alternative, you can select both ``object`` (for pandas 2.x) and
202+
``"string"`` (for pandas 3.x; which will also select the default ``str`` dtype
203+
and does not error on pandas 2.x):
204+
205+
.. code-block:: python
206+
207+
# can use ``include=["str"]`` for pandas >= 3
208+
>>> df.select_dtypes(include=["object", "string"])
209+
198210
199211
The missing value sentinel is now always NaN
200212
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)