Skip to content

Commit 44f7660

Browse files
committed
Simplify encode_categorical logic slightly
1 parent a784a77 commit 44f7660

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

janitor/functions/encode_categorical.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,11 @@ def encode_categorical(
112112
# or user supplies specific categories to create the categorical
113113
if column_names is not None:
114114
check("column_names", column_names, [list, tuple, Hashable])
115-
if isinstance(column_names, (list, tuple)):
116-
check_column(df, column_names)
117-
dtypes = {col: "category" for col in column_names}
118-
return df.astype(dtypes)
119115
if isinstance(column_names, Hashable):
120-
check_column(df, [column_names])
121-
return df.astype({column_names: "category"})
116+
column_names = [column_names]
117+
check_column(df, column_names)
118+
dtypes = {col: "category" for col in column_names}
119+
return df.astype(dtypes)
122120

123121
return _computations_as_categorical(df, **kwargs)
124122

0 commit comments

Comments
 (0)