-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Clean up DataFrame.setitem behavior for duplicate columns #39403
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
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9ce8713
Clean up DataFrame.setitem behavior for duplicate columns
phofl d9c8026
Add gh reference
phofl 4d57974
Move function
phofl d0bdc78
Remove type
phofl 6f5f419
Add note
phofl e0c047e
Adjust test
phofl 9a82e6c
Add spaces
phofl 2dad847
Add raises section
phofl ee4a849
Add types
phofl 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -376,6 +376,27 @@ def unpack_1tuple(tup): | |
return tup | ||
|
||
|
||
def check_key_length(columns, key, value): | ||
""" | ||
Checks if a key used as indexer has the same length as the columns it is | ||
associated with. | ||
|
||
Parameters | ||
---------- | ||
columns: Index The columns of the DataFrame to index. | ||
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. space between "columns" and colon, same on the next two lines 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. Thx |
||
key: A list-like of keys to index with. | ||
value: The value to set for the keys. | ||
|
||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
if columns.is_unique: | ||
if len(value.columns) != len(key): | ||
raise ValueError("Columns must be same length as key") | ||
else: | ||
# Missing keys in columns are represented as -1 | ||
if len(columns.get_indexer_non_unique(key)[0]) != len(value.columns): | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
raise ValueError("Columns must be same length as key") | ||
|
||
|
||
# ----------------------------------------------------------- | ||
# Public indexer validation | ||
|
||
|
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
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.
can you type as much as you can here
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.
We would have to type wiht Index and DataFrame causing circular imports. Is there a way around this?
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.
do the import inside a
if TYPE_CHECKING:
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.
Sorry, should have said that I have already tried this. If using TYPE_CHECKING and typing the signature (not the return value) this raises
NameError: name 'DataFrame' is not defined
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.
Did not know about the future import. Thx for the help