Skip to content

Commit a027753

Browse files
authored
TST/ENH: Enabel encode_categorical handle 2 (or more ) dimensions array (#1153)
* convert to ndarray first * simplify a bit `arr_ndim` only comes once * Update CHANGELOG.md
1 parent ae01b7d commit a027753

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- [BUG] Force `math.softmax` returning `Series`. PR #1139 @Zeroto521
1919
- [INF] Set independent environment for building documentation. PR #1141 @Zeroto521
2020
- [DOC] Add local documentation preview via github action artifact. PR #1149 @Zeroto521
21+
- [ENH] Enabel `encode_categorical` handle 2 (or more ) dimensions array. PR #1153 @Zeroto521
2122

2223
## [v0.23.1] - 2022-05-03
2324

janitor/functions/encode_categorical.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
from enum import Enum
33
from typing import Hashable, Iterable, Union
44

5-
import pandas_flavor as pf
5+
import numpy as np
66
import pandas as pd
7+
import pandas_flavor as pf
78
from pandas.api.types import is_list_like
89

910
from janitor.utils import check, check_column, deprecated_alias
@@ -191,10 +192,9 @@ def _as_categorical_checks(df: pd.DataFrame, **kwargs) -> dict:
191192
raise TypeError(f"{value} should be list-like or a string.")
192193
if is_list_like(value):
193194
if not hasattr(value, "shape"):
194-
value = pd.Index([*value])
195+
value = np.asarray(value)
195196

196-
arr_ndim = value.ndim
197-
if (arr_ndim != 1) or isinstance(value, pd.MultiIndex):
197+
if (value.ndim != 1) or isinstance(value, pd.MultiIndex):
198198
raise ValueError(
199199
f"{value} is not a 1-D array. "
200200
"Kindly provide a 1-D array-like object."

0 commit comments

Comments
 (0)