Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] generic select function #1187

Merged
merged 13 commits into from
Nov 8, 2022
Prev Previous commit
ensure booleans are converted into arrays
  • Loading branch information
samukweku committed Nov 7, 2022
commit 78620cb5c90c5911dd84dbac1c64ece564cb5e91
11 changes: 6 additions & 5 deletions janitor/functions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def _index_dispatch(arg, df, axis): # noqa: F811
f"{arg} is a boolean dtype and has wrong length: "
f"{len(arg)} instead of {len(index)}"
)
return arg
return np.asanyarray(arg)
try:

if isinstance(arg, pd.Series):
Expand Down Expand Up @@ -540,11 +540,12 @@ def _index_dispatch(arg, df, axis): # noqa: F811
# or materialized if possible;
# this offers more performance
if len(indices) == 1:
if isinstance(indices[0], int):
if is_scalar(indices[0]):
return indices
if is_list_like(indices[0]):
return np.asanyarray(indices[0])
return indices[0]
indices = indices[0]
if is_list_like(indices):
indices = np.asanyarray(indices)
return indices
contents = []
for arr in indices:
if is_list_like(arr):
Expand Down