Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
ENH: column label filtering via regexes to work for numeric names #10384
Conversation
|
can you add some tests? |
jreback
added the
Indexing
label
Jun 18, 2015
jreback
changed the title from
Update generic.py to ENH: column label filtering via regexes to work for numeric names
Jun 18, 2015
|
For search(x) -> search(str(x))? |
|
Any advice on what to add or where? I don't see any existing tests for this function... |
|
look in |
jreback
added this to the
0.17.0
milestone
Jul 3, 2015
jreback
added the
API Design
label
Jul 3, 2015
|
Thanks Jeff! Added the test. Let me know what you think... |
jreback
commented on an outdated diff
Jul 3, 2015
| @@ -10755,7 +10755,11 @@ 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 | ||
| + df = DataFrame(0., index=[0, 1, 2], columns=[0, 1, 'A1', 'B']) |
jreback
Contributor
|
jreback
commented on an outdated diff
Jul 3, 2015
| @@ -10755,7 +10755,11 @@ 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 | ||
| + df = DataFrame(0., index=[0, 1, 2], columns=[0, 1, 'A1', 'B']) | ||
| + filtered = df.filter(regex='^[0-9]+$') | ||
| + self.assertEqual(len(filtered.columns), 2) |
jreback
Contributor
|
|
add a not in whatsnew/0.17.0. Put in Other Enhancements section What would this do in 0.16.2 (if you passed the regex), not fitler anything? or raise? |
cyrusmaher
added some commits
Jul 3, 2015
|
Done! In 0.16.2 |
jreback
commented on an outdated diff
Jul 3, 2015
| @@ -26,7 +26,8 @@ New features | ||
| Other enhancements | ||
| ^^^^^^^^^^^^^^^^^^ | ||
| - | ||
| +- `regex` argument to DataFrame.filter now handles numeric column names instead of raising an exception. |
jreback
Contributor
|
jreback
commented on an outdated diff
Jul 3, 2015
| @@ -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']) | ||
| + filtered = df.filter(regex='^[0-9]+$') | ||
| + self.assertEqual(len(filtered.columns), 2) |
jreback
Contributor
|
|
when you are all done, pls rebase/squash see contributing docs here |
cyrusmaher
added some commits
Jun 18, 2015
|
I'm having trouble with squashing the commits. I don't have a ton of experience with git, so I'm not sure what to do next. Below is the message. Seems to have to do with a merge conflict in test_frame? Any advice?
|
|
contributing docs are here: http://pandas.pydata.org/pandas-docs/stable/contributing.html you have a conflict and need to fix it |
cyrusmaher
added some commits
Jun 18, 2015
|
Hmm, when I rebase it detects conflicts, then I resolve them using |
cyrusmaher
referenced
this pull request
Jul 4, 2015
Closed
`regex` option for `DataFrame.filter` raises error on numeric column names #10506
|
FYI, you don't normally need to add an issue if you just create a PR (like you did), but no biggie. |
|
I rebase you: https://travis-ci.org/jreback/pandas/builds/69631109 FYI don't use merge master. This is not pandas standard practice. This makes rebasing much more difficult. |
|
merged via bfe5a7f thanks! |
cyrusmaher commentedJun 18, 2015
Simple fix to allow regex filtering to work for numeric column labels, e.g. df.filter(regex="[12][34]")
closes #10506