Commit 40602f9e authored by Yu-Yang Huang's avatar Yu-Yang Huang Committed by Guolin Ke
Browse files

Do not map NaN in pandas categorical columns to -1 (#1226)

parent 3645c2fa
......@@ -251,7 +251,7 @@ def _data_from_pandas(data, feature_name, categorical_feature, pandas_categorica
data[col] = data[col].cat.set_categories(category)
if len(cat_cols): # cat_cols is pandas Index object
data = data.copy() # not alter origin DataFrame
data[cat_cols] = data[cat_cols].apply(lambda x: x.cat.codes)
data[cat_cols] = data[cat_cols].apply(lambda x: x.cat.codes).replace({-1: np.nan})
if categorical_feature is not None:
if feature_name is None:
feature_name = list(data.columns)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment