@@ -480,31 +480,34 @@ def is_view(self) -> bool:
480480 def is_single_block (self ) -> bool :
481481 return False
482482
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+
483490 def get_bool_data (self , copy : bool = False ) -> ArrayManager :
484491 """
492+ Select columns that are bool-dtype.
493+
485494 Parameters
486495 ----------
487496 copy : bool, default False
488497 Whether to copy the blocks
489498 """
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 ))
495500
496501 def get_numeric_data (self , copy : bool = False ) -> ArrayManager :
497502 """
503+ Select columns that have a numeric dtype.
504+
498505 Parameters
499506 ----------
500507 copy : bool, default False
501508 Whether to copy the blocks
502509 """
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 ))
508511
509512 def copy (self : T , deep = True ) -> T :
510513 """
0 commit comments