-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Bug in DataFrame.drop_duplicates for empty DataFrame throws error #22394
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 10 commits
03af0c1
79ee155
31f6099
6eb53f6
de745bb
3a5d97d
1f58a85
4f299c5
cab0958
68d69db
fb8845d
1f12545
20c03ef
fc61899
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 |
---|---|---|
|
@@ -263,6 +263,21 @@ def test_drop_duplicates_tuple(): | |
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize('df', [ | ||
DataFrame(), | ||
DataFrame(columns=[]), | ||
DataFrame(columns=['A', 'B', 'C']), | ||
DataFrame(index=[]), | ||
DataFrame(index=['A', 'B', 'C']) | ||
]) | ||
def test_drop_duplicates_empty(df): | ||
# GH 20516 | ||
result = df.drop_duplicates() | ||
if df.columns.empty is False: | ||
df = DataFrame(columns=[]) | ||
tm.assert_frame_equal(result, df) | ||
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. This tests feels a bit tricky to me. So, when there are columns, we set them to an empty list. So, that would be the same as simply using as expected value But not sure if I'm missing something, but I'd expect 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. Please check the closed issue of #22409. 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. I don't think the problem may be your approach implementing this story. I agree on what @WillAyd said in #22409, but not in the side effect in this PR. I guess But the case here with And in your test you're asserting that the return will be 0 columns and 0 rows. Am I right? Does it makes sense? 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. Yeah. However, if we want to leave the column when there exists no value, then we'd need to change the 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. Oh, I understand the problem now. There is some magic on That's why your approach is not working as expected. You may try to check with 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. can you add a test case with 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. Sure. |
||
|
||
|
||
def test_drop_duplicates_NA(): | ||
# none | ||
df = DataFrame({'A': [None, None, 'foo', 'bar', | ||
|
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.
raises an error