-
Notifications
You must be signed in to change notification settings - Fork 861
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
Applying to iloc of pandas data frame #500
Conversation
rasbt#499 Bug fix for selecting columns from the list and it works not only a list but the index of pandas.
Hello @tetrar124! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on February 13, 2019 at 07:57 Hours UTC |
add error message and comment for using it
add error message and comment for using it
Thanks for the PR. However, instead doing a try-except, I think the following could solve the problem better? (Haven't tested it, but what do you think? Does that cover your use case issue?) if hasattr(X, 'loc') or hasattr(X, 'iloc'):
types = {type(i) for i in self.cols}
if len(types) > 1:
raise ValueError('Elements in `cols` should be all of the same data type.')
if isinstance(cols[0], int):
t = X.iloc[:, self.cols].values
elif isinstance(cols[0], str):
t = X.loc[:, self.cols].values
else:
raise ValueError('Elements in `cols` should be either `int` or `str`.') |
I checked your code on my environment, your code works well (I changed only cols[0] to self.cols[0]).
Thank you for your cooperation. |
Update for pandas iloc
Update for pandas iloc
Thanks for working on this PR! Just as a tip to make the debugging smoother/faster (since the CI is very slow), you can also test your code locally by running
to see if there are any issues with the code. |
for coverage
elif to if
Sorry, I return elif to if. The reason for using elif is only for the coverage. I checked new lines with nose and flask8, and there are no errors other than 'line too long' from the new comment lines for ValueError. |
Ok thanks :)! Btw don't worry about minor changes regarding the coverage too much. Can you please make the line < 79 chars though (splitting it over two lines) -- we decided to strictly enforce PEP8 at some point so that the library won't become too messy over time by making exceptions. |
Could you also add an additional unit test for using a DataFrame with integer column names to make sure it works correctly? (I think we don't have that one yet) :) |
I made the data frame with columns whose names were only integer values, and I checked the type of these columns names showed int. |
Thanks for testing. We should add a unit test though so that we can ensure that the behavior doesn't break in future. I just added a unit test and changelog entry to this PR. Let me know if you have any further comments. Otherwise, I think it's good to merge if/when the CI tests pass. Thanks for the PR! |
Description
Bug fix for selecting columns and add new features for the name of the columns of pandas data frame.
Related issues or pull requests
Pull Request Checklist
./docs/sources/CHANGELOG.md
file (if applicable)./mlxtend/*/tests
directories (if applicable)mlxtend/docs/sources/
(if applicable)nosetests ./mlxtend -sv
and make sure that all unit tests pass (for small modifications, it might be sufficient to only run the specific test file, e.g.,nosetests ./mlxtend/classifier/tests/test_stacking_cv_classifier.py -sv
)flake8 ./mlxtend