Skip to content

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

Merged
merged 5 commits into from
Nov 22, 2017

Conversation

Licht-T
Copy link
Contributor

@Licht-T Licht-T commented Nov 12, 2017

Copy link
Contributor

@jreback jreback left a 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

@@ -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)
Copy link
Contributor

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

Copy link
Contributor

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'])
Copy link
Contributor

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

Copy link
Contributor

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

@jreback jreback added Bug Unicode Unicode strings labels Nov 12, 2017
@pep8speaks
Copy link

pep8speaks commented Nov 21, 2017

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

@Licht-T
Copy link
Contributor Author

Licht-T commented Nov 21, 2017

Thanks @jreback, now fixed!

@codecov
Copy link

codecov bot commented Nov 21, 2017

Codecov Report

Merging #18238 into master will decrease coverage by 0.02%.
The diff coverage is 73.33%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 89.14% <73.33%> (-0.01%) ⬇️
#single 39.61% <13.33%> (-0.07%) ⬇️
Impacted Files Coverage Δ
pandas/core/generic.py 95.73% <100%> (ø) ⬆️
pandas/compat/__init__.py 58.18% <60%> (+0.08%) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.8% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c4a2cd3...3c58fcb. Read the comment docs.

@jreback jreback added this to the 0.21.1 milestone Nov 22, 2017
@jreback jreback merged commit ec065b2 into pandas-dev:master Nov 22, 2017
@jreback
Copy link
Contributor

jreback commented Nov 22, 2017

thanks @Licht-T very nice!

TomAugspurger pushed a commit to TomAugspurger/pandas that referenced this pull request Dec 8, 2017
TomAugspurger pushed a commit that referenced this pull request Dec 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Unicode Unicode strings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: .filter with unicode labels when can't encode
4 participants