-
-
Notifications
You must be signed in to change notification settings - Fork 18.8k
ENH: Implement DataFrame.select #61527
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
+224
−0
Closed
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0f64c13
ENH: Implement DataFrame.select
datapythonista bf2a9ea
Making select work with a list parameter
datapythonista 92cb1e7
Improve docs
datapythonista 527d1d7
Typing
datapythonista eb91004
Merge branch 'main' into implement_select
datapythonista dd4f63d
Typing select *args
datapythonista 9e49c96
Merge remote-tracking branch 'upstream/main' into implement_select
datapythonista 76b5714
Merge branch 'implement_select' of github.com:datapythonista/pandas i…
datapythonista e93238a
Better error message when lists are passed as parameters
datapythonista 09e2d9f
Use TypeError instead of ValueError
datapythonista File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So the problem with this typing is that this will accept
select(["a,"b"], ["c", "d"])
That's why I suggested the following:
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.
Your proposal is using a default mutable parameter, which is considered a bad practice (for good reason), and I assume will also break the CI as ruff has a rule for it. I understand that the current implementation typing isn't perfect, and it could be more strict. I added a better error message if someone uses
select(["a,"b"], ["c", "d"])
, but I think this is the best we can do.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.
The other way of handling that is to make the last part of the sequence of declarations:
Then in the code if
arg0 is None
, then eitherlen(args)==0
(in which case it is an empty DF), or you just useargs
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.
With this the typing allows
df.select(None, "col1", "col2")
, which I don't see as an improvement to the what you are trying to solve.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.
That's not correct IF you include the overloads. If overloads are included, then only the overloads can be matched.
The type checkers ONLY check the overloads, not the final declaration. So
select(None, "col1", "col2")
would be flagged by the type checker.