-
Notifications
You must be signed in to change notification settings - Fork 173
TST/ENH: Enabel encode_categorical handle 2 (or more ) dimensions array
#1153
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
TST/ENH: Enabel encode_categorical handle 2 (or more ) dimensions array
#1153
Conversation
`arr_ndim` only comes once
| 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]) |
There was a problem hiding this comment.
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.
| import numpy as np | ||
| import pandas as pd | ||
| import pandas_flavor as pf | ||
| from pandas.api.types import is_list_like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lint via isort
Codecov Report
@@ Coverage Diff @@
## dev #1153 +/- ##
=======================================
Coverage 97.34% 97.34%
=======================================
Files 77 77
Lines 3240 3240
=======================================
Hits 3154 3154
Misses 86 86 |
|
|
||
| arr_ndim = value.ndim | ||
| if (arr_ndim != 1) or isinstance(value, pd.MultiIndex): | ||
| if (value.ndim != 1) or isinstance(value, pd.MultiIndex): |
There was a problem hiding this comment.
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
PR Description
Please describe the changes proposed in the pull request:
test_categories_ndim_array_gt_1_in_kwargsshould raise error inpyjanitor/janitor/functions/encode_categorical.py
Lines 196 to 201 in ae01b7d
when input is
array = [[1, 1, 2, 2], ["red", "blue", "red", "blue"]]thendimofpd.Index(array)is 1 not 2.It's better to convert ndarray object first.
This PR resolves #1143.
PR Checklist
Please ensure that you have done the following:
<your_username>:dev, but rather from<your_username>:<feature-branch_name>.AUTHORS.md.CHANGELOG.mdunder the latest version header (i.e. the one that is "on deck") describing the contribution.Automatic checks
There will be automatic checks run on the PR. These include:
Relevant Reviewers
Please tag maintainers to review.