Skip to content

BUG: Duplicated returns boolean dataframe #25234

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 2 commits into from
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.24.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Fixed Regressions

- Fixed issue in ``DataFrame`` construction with passing a mixed list of mixed types could segfault. (:issue:`25075`)

- Fixed regression in :meth:`DataFrame.duplicated()`, where empty dataframe was not returning a boolean dtyped Series. (:issue:`25184`)

.. _whatsnew_0242.enhancements:

Enhancements
Expand Down
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Performance Improvements
Bug Fixes
~~~~~~~~~

-

Categorical
^^^^^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4636,7 +4636,7 @@ def duplicated(self, subset=None, keep='first'):
from pandas._libs.hashtable import duplicated_int64, _SIZE_HINT_LIMIT

if self.empty:
return Series()
return Series(dtype=bool)

def f(vals):
labels, shape = algorithms.factorize(
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/frame/test_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ def test_drop_duplicates():
assert df.duplicated(keep=keep).sum() == 0


def test_duplicated_on_empty_frame():
# GH 25184

df = DataFrame(columns=['a', 'b'])
dupes = df.duplicated('a')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

result =
expected =
tm.assert_frame_equal(result, expected)


result = df[dupes]
expected = df.copy()
tm.assert_frame_equal(result, expected)


def test_drop_duplicates_with_duplicate_column_names():
# GH17836
df = DataFrame([
Expand Down