Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions janitor/functions/encode_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from enum import Enum
from typing import Hashable, Iterable, Union

import pandas_flavor as pf
import numpy as np
import pandas as pd
import pandas_flavor as pf
from pandas.api.types import is_list_like
Comment on lines +5 to 8
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint via isort


from janitor.utils import check, check_column, deprecated_alias
Expand Down Expand Up @@ -191,10 +192,9 @@ def _as_categorical_checks(df: pd.DataFrame, **kwargs) -> dict:
raise TypeError(f"{value} should be list-like or a string.")
if is_list_like(value):
if not hasattr(value, "shape"):
value = pd.Index([*value])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will convert value to pd.Index again in line 203.

value = np.asarray(value)

arr_ndim = value.ndim
if (arr_ndim != 1) or isinstance(value, pd.MultiIndex):
if (value.ndim != 1) or isinstance(value, pd.MultiIndex):
Copy link
Member Author

@Zeroto521 Zeroto521 Aug 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arr_ndim only comes once, so use value.ndim directly

raise ValueError(
f"{value} is not a 1-D array. "
"Kindly provide a 1-D array-like object."
Expand Down