@@ -3488,44 +3488,30 @@ def _get_info_slice(obj, indexer):
3488
3488
)
3489
3489
)
3490
3490
3491
- # empty include/exclude -> defaults to True
3492
- # three cases (we've already raised if both are empty)
3493
- # case 1: empty include, nonempty exclude
3494
- # we have True, True, ... True for include, same for exclude
3495
- # in the loop below we get the excluded
3496
- # and when we call '&' below we get only the excluded
3497
- # case 2: nonempty include, empty exclude
3498
- # same as case 1, but with include
3499
- # case 3: both nonempty
3500
- # the "union" of the logic of case 1 and case 2:
3501
- # we get the included and excluded, and return their logical and
3502
- include_these = Series (not bool (include ), index = self .columns )
3503
- exclude_these = Series (not bool (exclude ), index = self .columns )
3504
-
3491
+ # We raise when both include and exclude are empty
3492
+ # Hence, we can just shrink the columns we want to keep
3493
+ keep_these = Series (True , index = self .columns )
3505
3494
unique_dtypes = self .dtypes .unique ()
3506
3495
3507
- if include :
3508
- included_dtypes = [
3496
+ def filter_unique_dtypes_on ( selection , unqiue_dtypes ) :
3497
+ result = [
3509
3498
dtype
3510
3499
for dtype in unique_dtypes
3511
3500
if any (
3512
- issubclass (dtype .type , included_type ) for included_type in include
3501
+ issubclass (dtype .type , selected_type ) for selected_type in selection
3513
3502
)
3514
3503
]
3515
- include_these |= self .dtypes .isin (included_dtypes )
3504
+ return result
3505
+
3506
+ if include :
3507
+ included_dtypes = filter_unique_dtypes_on (include , unique_dtypes )
3508
+ keep_these &= self .dtypes .isin (included_dtypes )
3516
3509
3517
3510
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 )
3511
+ excluded_dtypes = filter_unique_dtypes_on (exclude , unique_dtypes )
3512
+ keep_these &= ~ self .dtypes .isin (excluded_dtypes )
3526
3513
3527
- dtype_indexer = include_these & exclude_these
3528
- return self .loc [_get_info_slice (self , dtype_indexer )]
3514
+ return self .loc [_get_info_slice (self , keep_these )]
3529
3515
3530
3516
def insert (self , loc , column , value , allow_duplicates = False ):
3531
3517
"""
0 commit comments