Skip to content

Commit

Permalink
Simplify encode_categorical logic slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
thatlittleboy committed Mar 1, 2022
1 parent a784a77 commit 44f7660
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions janitor/functions/encode_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,11 @@ def encode_categorical(
# or user supplies specific categories to create the categorical
if column_names is not None:
check("column_names", column_names, [list, tuple, Hashable])
if isinstance(column_names, (list, tuple)):
check_column(df, column_names)
dtypes = {col: "category" for col in column_names}
return df.astype(dtypes)
if isinstance(column_names, Hashable):
check_column(df, [column_names])
return df.astype({column_names: "category"})
column_names = [column_names]
check_column(df, column_names)
dtypes = {col: "category" for col in column_names}
return df.astype(dtypes)

return _computations_as_categorical(df, **kwargs)

Expand Down

0 comments on commit 44f7660

Please sign in to comment.