Skip to content

Commit 4728f0b

Browse files
meeseeksmachinejreback
authored andcommitted
Backport PR #25234: BUG: Duplicated returns boolean dataframe (#25267)
1 parent 5481dd1 commit 4728f0b

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

doc/source/whatsnew/v0.24.2.rst

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Fixed Regressions
2424
- Fixed issue in ``DataFrame`` construction with passing a mixed list of mixed types could segfault. (:issue:`25075`)
2525
- Fixed regression in :meth:`DataFrame.apply` causing ``RecursionError`` when ``dict``-like classes were passed as argument. (:issue:`25196`)
2626

27+
- Fixed regression in :meth:`DataFrame.duplicated()`, where empty dataframe was not returning a boolean dtyped Series. (:issue:`25184`)
28+
2729
.. _whatsnew_0242.enhancements:
2830

2931
Enhancements

doc/source/whatsnew/v0.25.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ Performance Improvements
6969
Bug Fixes
7070
~~~~~~~~~
7171

72+
-
73+
7274
Categorical
7375
^^^^^^^^^^^
7476

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4661,7 +4661,7 @@ def duplicated(self, subset=None, keep='first'):
46614661
from pandas._libs.hashtable import duplicated_int64, _SIZE_HINT_LIMIT
46624662

46634663
if self.empty:
4664-
return Series()
4664+
return Series(dtype=bool)
46654665

46664666
def f(vals):
46674667
labels, shape = algorithms.factorize(

pandas/tests/frame/test_duplicates.py

+11
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,17 @@ def test_drop_duplicates():
182182
assert df.duplicated(keep=keep).sum() == 0
183183

184184

185+
def test_duplicated_on_empty_frame():
186+
# GH 25184
187+
188+
df = DataFrame(columns=['a', 'b'])
189+
dupes = df.duplicated('a')
190+
191+
result = df[dupes]
192+
expected = df.copy()
193+
tm.assert_frame_equal(result, expected)
194+
195+
185196
def test_drop_duplicates_with_duplicate_column_names():
186197
# GH17836
187198
df = DataFrame([

0 commit comments

Comments
 (0)