Skip to content

Commit 04880bb

Browse files
committed
more vectorization in select_dtypes
1 parent a54e1b4 commit 04880bb

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

pandas/core/frame.py

+20-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"""
1111
import collections
1212
from collections import OrderedDict, abc
13-
import functools
1413
from io import StringIO
1514
import itertools
1615
import sys
@@ -3503,16 +3502,27 @@ def _get_info_slice(obj, indexer):
35033502
include_these = Series(not bool(include), index=self.columns)
35043503
exclude_these = Series(not bool(exclude), index=self.columns)
35053504

3506-
def is_dtype_instance_mapper(idx, dtype):
3507-
return idx, functools.partial(issubclass, dtype.type)
3505+
unique_dtypes = self.dtypes.unique()
35083506

3509-
for idx, f in itertools.starmap(
3510-
is_dtype_instance_mapper, enumerate(self.dtypes)
3511-
):
3512-
if include: # checks for the case of empty include or exclude
3513-
include_these.iloc[idx] = any(map(f, include))
3514-
if exclude:
3515-
exclude_these.iloc[idx] = not any(map(f, exclude))
3507+
if include:
3508+
included_dtypes = [
3509+
dtype
3510+
for dtype in unique_dtypes
3511+
if any(
3512+
issubclass(dtype.type, included_type) for included_type in include
3513+
)
3514+
]
3515+
include_these |= self.dtypes.isin(included_dtypes)
3516+
3517+
if exclude:
3518+
excluded_dtypes = [
3519+
dtype
3520+
for dtype in unique_dtypes
3521+
if any(
3522+
issubclass(dtype.type, excluded_type) for excluded_type in exclude
3523+
)
3524+
]
3525+
exclude_these |= ~self.dtypes.isin(excluded_dtypes)
35163526

35173527
dtype_indexer = include_these & exclude_these
35183528
return self.loc[_get_info_slice(self, dtype_indexer)]

0 commit comments

Comments
 (0)