-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: column label filtering via regexes to work for numeric names #10384
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
Changes from 4 commits
ac58777
ac90352
b70b9c1
3a9934d
12d79e7
ccc7490
009422c
b46133f
5bd0a4b
88a8e3e
49b607f
2a9ddd1
0d3af4c
94626cc
3bb6d05
86d523a
f562f7f
d9c4523
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10741,7 +10741,7 @@ def test_filter(self): | |
idx = self.frame.index[0:4] | ||
filtered = self.frame.filter(idx, axis='index') | ||
expected = self.frame.reindex(index=idx) | ||
assert_frame_equal(filtered,expected) | ||
assert_frame_equal(filtered, expected) | ||
|
||
# like | ||
fcopy = self.frame.copy() | ||
|
@@ -10755,6 +10755,16 @@ def test_filter(self): | |
df = DataFrame(0., index=[0, 1, 2], columns=[0, 1, '_A', '_B']) | ||
filtered = df.filter(like='_') | ||
self.assertEqual(len(filtered.columns), 2) | ||
|
||
# regex with ints in column names | ||
# from PR #10384 | ||
df = DataFrame(0., index=[0, 1, 2], columns=[0, 1, 'A1', 'B']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add the issue number as a comment (this PR number since no associated issue) |
||
filtered = df.filter(regex='^[0-9]+$') | ||
self.assertEqual(len(filtered.columns), 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do the test again with all number columns that are strings, e.g. on the comparision do
IOW construct the expected manually There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use an you will need to explicty construct the expected, e.g. something like
also change the test a bit to put the numerics not all at the beginning (e.g. put one in the middle or end) |
||
|
||
expected = DataFrame(0., index=[0, 1, 2], columns=[0, 1, '0', '1']) | ||
filtered = expected.filter(regex='^[0-9]+$') # shouldn't remove anything | ||
self.assert_frame_equal(filtered, expected) | ||
|
||
# pass in None | ||
with assertRaisesRegexp(TypeError, 'Must pass'): | ||
|
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.
use double backticks here (and around
DateFrame.filter
)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 (this PR number) onto the end (see how the other issues are done)
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.
say instead of raising
ValueError