-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix filter method so that accepts byte and unicode column names #18238
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
Conversation
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.
pls add a whatsnew for 0.21.1
pandas/core/generic.py
Outdated
@@ -3218,14 +3219,22 @@ def filter(self, items=None, like=None, regex=None, axis=None): | |||
**{name: [r for r in items if r in labels]}) | |||
elif like: | |||
def f(x): | |||
if not isinstance(x, string_types): | |||
if isinstance(x, binary_type): | |||
x = bytes_to_str(x) |
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.
hmm can you codify these into a function in pandas/compat/__init__.py
, maybe to_str
, and add a doc-string so its clear what it does, put it right below the u/u_safe
functions
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.
make it clear that you are turning bytes, non-strings into strings
@@ -884,6 +884,22 @@ def test_filter_regex_search(self): | |||
exp = df[[x for x in df.columns if 'BB' in x]] | |||
assert_frame_equal(result, exp) | |||
|
|||
@pytest.mark.parametrize('exp', ['a', u'a']) |
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.
can you add the example from the issue, e.g. with a non-ascii character
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.
add the issue number as a comment on the tests
fd8d1d5
to
e46bc00
Compare
Hello @Licht-T! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on November 21, 2017 at 16:25 Hours UTC |
75b66bb
to
752f9f1
Compare
Thanks @jreback, now fixed! |
Codecov Report
@@ Coverage Diff @@
## master #18238 +/- ##
==========================================
- Coverage 91.36% 91.34% -0.03%
==========================================
Files 164 164
Lines 49733 49743 +10
==========================================
- Hits 45439 45436 -3
- Misses 4294 4307 +13
Continue to review full report at Codecov.
|
thanks @Licht-T very nice! |
…andas-dev#18238) (cherry picked from commit ec065b2)
git diff upstream/master -u -- "*.py" | flake8 --diff