diff --git a/python/pyspark/pandas/frame.py b/python/pyspark/pandas/frame.py index e5aaecbb64fd..2238d044cefe 100644 --- a/python/pyspark/pandas/frame.py +++ b/python/pyspark/pandas/frame.py @@ -11262,15 +11262,9 @@ def _bool_column_labels(self, column_labels: List[Label]) -> List[Label]: """ Filter column labels of boolean columns (without None). """ - bool_column_labels = [] - for label in column_labels: - psser = self._psser_for(label) - if is_bool_dtype(psser): - # Rely on dtype rather than spark type because - # columns that consist of bools and Nones should be excluded - # if bool_only is True - bool_column_labels.append(label) - return bool_column_labels + # Rely on dtype rather than spark type because columns that consist of bools and + # Nones should be excluded if bool_only is True + return [label for label in column_labels if is_bool_dtype(self._psser_for(label))] def _result_aggregated( self, column_labels: List[Label], scols: Sequence[PySparkColumn]