Skip to content

Commit e1652c6

Browse files
author
PaulWestenthanner
committed
support for older pandas versions
1 parent f80054c commit e1652c6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

category_encoders/ordinal.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ def ordinal_encoding(X_in, mapping=None, cols=None, handle_unknown='value', hand
195195

196196
# Convert to object to accept np.nan (dtype string doesn't)
197197
# fillna changes None and pd.NA to np.nan
198-
with pd.option_context('future.no_silent_downcasting', True):
198+
try:
199+
with pd.option_context('future.no_silent_downcasting', True):
200+
X[column] = X[column].astype("object").fillna(np.nan).map(col_mapping)
201+
except pd._config.config.OptionError: # old pandas versions
199202
X[column] = X[column].astype("object").fillna(np.nan).map(col_mapping)
200203
if util.is_category(X[column].dtype):
201204
nan_identity = col_mapping.loc[col_mapping.index.isna()].array[0]

0 commit comments

Comments
 (0)