|
10 | 10 | """
|
11 | 11 | import collections
|
12 | 12 | from collections import OrderedDict, abc
|
13 |
| -import functools |
14 | 13 | from io import StringIO
|
15 | 14 | import itertools
|
16 | 15 | import sys
|
@@ -3503,16 +3502,27 @@ def _get_info_slice(obj, indexer):
|
3503 | 3502 | include_these = Series(not bool(include), index=self.columns)
|
3504 | 3503 | exclude_these = Series(not bool(exclude), index=self.columns)
|
3505 | 3504 |
|
3506 |
| - def is_dtype_instance_mapper(idx, dtype): |
3507 |
| - return idx, functools.partial(issubclass, dtype.type) |
| 3505 | + unique_dtypes = self.dtypes.unique() |
3508 | 3506 |
|
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) |
3516 | 3526 |
|
3517 | 3527 | dtype_indexer = include_these & exclude_these
|
3518 | 3528 | return self.loc[_get_info_slice(self, dtype_indexer)]
|
|
0 commit comments