-
-
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
Changes from 4 commits
9ce8713
d9c8026
4d57974
d0bdc78
6f5f419
e0c047e
9a82e6c
2dad847
ee4a849
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 |
---|---|---|
|
@@ -376,6 +376,25 @@ 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 | ||
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. newline after """ 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 |
||
associated with. | ||
|
||
Parameters | ||
---------- | ||
columns: 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.
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. changed |
||
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: | ||
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 | ||
|
||
|
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