Skip to content

API: DataFrame.select_dtypes should accept scalar #16855

Closed
@chris-b1

Description

@chris-b1
In [164]: df = pd.DataFrame({'a': [1, 2, 3], 'b': ['a', 'b', 'c']})

In [165]: df.select_dtypes(include='object')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-165-04044faa1a5a> in <module>()
----> 1 df.select_dtypes(include='object')

~\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\frame.py in select_dtypes(self, include, exclude)
   2355         include, exclude = include or (), exclude or ()
   2356         if not (is_list_like(include) and is_list_like(exclude)):
-> 2357             raise TypeError('include and exclude must both be non-string'
   2358                             ' sequences')
   2359         selection = tuple(map(frozenset, (include, exclude)))

TypeError: include and exclude must both be non-string sequences

In [166]: df.select_dtypes(include=['object'])
Out[166]: 
   b
0  a
1  b
2  c

Problem description

Only a convenience thing, but basically anywhere else we take list-likes, we accept a single string and I think should do the same here.

pandas 0.20.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions