Skip to content

Commit

Permalink
lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Sep 15, 2021
1 parent 49bad50 commit a301ecc
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions python-package/xgboost/data.py
Expand Up @@ -227,15 +227,13 @@ def _transform_pandas_df(
meta_type=None,
):
import pandas as pd
from pandas import MultiIndex, Int64Index, RangeIndex
from pandas.api.types import is_sparse, is_categorical_dtype

data_dtypes = data.dtypes
if not all(dtype.name in _pandas_dtype_mapper or is_sparse(dtype) or
(is_categorical_dtype(dtype) and enable_categorical)
for dtype in data_dtypes):
for dtype in data.dtypes):
bad_fields = [
str(data.columns[i]) for i, dtype in enumerate(data_dtypes)
str(data.columns[i]) for i, dtype in enumerate(data.dtypes)
if dtype.name not in _pandas_dtype_mapper
]

Expand All @@ -246,19 +244,19 @@ def _transform_pandas_df(

# handle feature names
if feature_names is None and meta is None:
if isinstance(data.columns, MultiIndex):
if isinstance(data.columns, pd.MultiIndex):
feature_names = [
' '.join([str(x) for x in i]) for i in data.columns
]
elif isinstance(data.columns, (Int64Index, RangeIndex)):
elif isinstance(data.columns, (pd.Int64Index, pd.RangeIndex)):
feature_names = list(map(str, data.columns))
else:
feature_names = data.columns.format()

# handle feature types
if feature_types is None and meta is None:
feature_types = []
for i, dtype in enumerate(data_dtypes):
for i, dtype in enumerate(data.dtypes):
if is_sparse(dtype):
feature_types.append(_pandas_dtype_mapper[dtype.subtype.name])
elif is_categorical_dtype(dtype) and enable_categorical:
Expand All @@ -269,7 +267,7 @@ def _transform_pandas_df(
# handle categorical codes.
transformed = pd.DataFrame()
if enable_categorical:
for i, dtype in enumerate(data_dtypes):
for i, dtype in enumerate(data.dtypes):
if is_categorical_dtype(dtype):
transformed[data.columns[i]] = data[data.columns[i]].cat.codes
else:
Expand Down

0 comments on commit a301ecc

Please sign in to comment.