@@ -480,31 +480,34 @@ def is_view(self) -> bool:
480
480
def is_single_block (self ) -> bool :
481
481
return False
482
482
483
+ def _get_data_subset (self , predicate : Callable ) -> ArrayManager :
484
+ indices = [i for i , arr in enumerate (self .arrays ) if predicate (arr )]
485
+ arrays = [self .arrays [i ] for i in indices ]
486
+ # TODO copy?
487
+ new_axes = [self ._axes [0 ], self ._axes [1 ][np .array (indices , dtype = "int64" )]]
488
+ return type (self )(arrays , new_axes , verify_integrity = False )
489
+
483
490
def get_bool_data (self , copy : bool = False ) -> ArrayManager :
484
491
"""
492
+ Select columns that are bool-dtype.
493
+
485
494
Parameters
486
495
----------
487
496
copy : bool, default False
488
497
Whether to copy the blocks
489
498
"""
490
- mask = np .array ([is_bool_dtype (t ) for t in self .get_dtypes ()], dtype = "object" )
491
- arrays = [self .arrays [i ] for i in np .nonzero (mask )[0 ]]
492
- # TODO copy?
493
- new_axes = [self ._axes [0 ], self ._axes [1 ][mask ]]
494
- return type (self )(arrays , new_axes )
499
+ return self ._get_data_subset (lambda arr : is_bool_dtype (arr .dtype ))
495
500
496
501
def get_numeric_data (self , copy : bool = False ) -> ArrayManager :
497
502
"""
503
+ Select columns that have a numeric dtype.
504
+
498
505
Parameters
499
506
----------
500
507
copy : bool, default False
501
508
Whether to copy the blocks
502
509
"""
503
- mask = np .array ([is_numeric_dtype (t ) for t in self .get_dtypes ()])
504
- arrays = [self .arrays [i ] for i in np .nonzero (mask )[0 ]]
505
- # TODO copy?
506
- new_axes = [self ._axes [0 ], self ._axes [1 ][mask ]]
507
- return type (self )(arrays , new_axes )
510
+ return self ._get_data_subset (lambda arr : is_numeric_dtype (arr .dtype ))
508
511
509
512
def copy (self : T , deep = True ) -> T :
510
513
"""
0 commit comments