Skip to content

ENH: add NDFrame.select_str #27340

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

Closed
wants to merge 1 commit into from

Conversation

topper-123
Copy link
Contributor

@topper-123 topper-123 commented Jul 11, 2019

Adds a method select_str to supplement select_dtypes. This PR is intended to be followed by a PR that deprecate NDFrame.filter.

I miss the most having a string focused axis-filtering method, and is NDFrame.filter a bit unfocused and badly named IMO. I think usage of parameter items in NDFrame.filter can just be replaced by recommending NDFrame.__getitem__ and parameter like is less useful than startswith and endswith (is less precise). So this is not a 100 % replacement for NDFrame.filter, but intends to make something that is more useful (IMO, of course).

This is not fully tested and need a whatsnew etc. but I would like to get some response before I go further.

@pep8speaks
Copy link

pep8speaks commented Jul 11, 2019

Hello @topper-123! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-07-11 20:38:22 UTC

@topper-123 topper-123 force-pushed the NDFrame.select_str branch from 8857c97 to c243435 Compare July 11, 2019 16:55
@topper-123 topper-123 changed the title ENH: add DataFrame.select_str ENH: add NDFrame.select_str Jul 11, 2019
@topper-123 topper-123 force-pushed the NDFrame.select_str branch 2 times, most recently from d5830b1 to e4345ab Compare July 11, 2019 19:54
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm not sure on the direction - so the original point was to implement this functionality into select right?


Parameters
----------
startswith: str, optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not just boil the signature down to regex?

Copy link
Contributor Author

@topper-123 topper-123 Jul 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, startswith and endswith are not cardinal points for me, just thought they are often used, so nicer for people who don't want/know how to use regexes.

return matcher.search(x) is not None

mapped = labels.map(f)
return self.loc(axis=axis)[mapped]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so I would instead implement

df.loc(regex=)[....] as an api, which turns the indexers into regexes.

@jreback jreback added the Indexing Related to indexing on series/frames, not to indexes themselves label Jul 11, 2019
@topper-123
Copy link
Contributor Author

Closing in favor of #27363

@topper-123 topper-123 closed this Jul 12, 2019
@topper-123 topper-123 deleted the NDFrame.select_str branch July 12, 2019 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename NDFrame.filter to .select?
4 participants