-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: loc.setitem raising ValueError when df has duplicate columns #39278
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 3 commits
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 |
---|---|---|
|
@@ -373,6 +373,15 @@ def test_setitem_string_column_numpy_dtype_raising(self): | |
expected = DataFrame([[1, 2, 5], [3, 4, 6]], columns=[0, 1, "0 - Name"]) | ||
tm.assert_frame_equal(df, expected) | ||
|
||
def test_setitem_empty_df_duplicate_columns(self): | ||
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. do we need tests for Series? 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. Don't think so, indexer has to be a tuple to land there, which is only valid for dataframes I think? 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. its weird, but you could do 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. Yep, definitely weird :) But this is already converted before reaching that point.
This results in |
||
# GH#38521 | ||
df = DataFrame(columns=["a", "b", "b"], dtype="float64") | ||
df.loc[:, "a"] = list(range(2)) | ||
expected = DataFrame( | ||
[[0, np.nan, np.nan], [1, np.nan, np.nan]], columns=["a", "b", "b"] | ||
) | ||
tm.assert_frame_equal(df, expected) | ||
|
||
|
||
class TestDataFrameSetItemSlicing: | ||
def test_setitem_slice_position(self): | ||
|
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.
lets separate this out into a nested condition and define
item_labels[indexer[info_axis]]
once, then reuse it on L1856There 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.
Done