Skip to content

Commit

Permalink
better management of column types
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMount committed Apr 29, 2021
1 parent a222c7a commit b9782de
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/vtreat/vtreat_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,16 @@ def pre_prep_frame(x, *, col_list, cols_to_copy, cat_cols=None):
if c in cset:
continue
bad_ind = vtreat.util.is_bad(x[c])
if ((cat_col_set is None) or (c not in cat_col_set)) and vtreat.util.can_convert_v_to_numeric(x[c]):
if cat_col_set is not None:
numeric_col = c not in cat_col_set
else:
numeric_col = vtreat.util.can_convert_v_to_numeric(x[c])
if numeric_col:
x[c] = vtreat.util.safe_to_numeric_array(x[c])
else:
# https://stackoverflow.com/questions/22231592/pandas-change-data-type-of-series-to-string
x[c] = x[c].astype(str)
x.loc[bad_ind, c] = numpy.nan
x.loc[bad_ind, c] = None
return x


Expand Down

0 comments on commit b9782de

Please sign in to comment.