Skip to content

Commit ca5b1df

Browse files
Sterling Paramorejreback
Sterling Paramore
authored andcommitted
BUG: Duplicated returns boolean dataframe (#25234)
1 parent 5f73594 commit ca5b1df

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
@@ -68,6 +68,8 @@ Performance Improvements
6868
Bug Fixes
6969
~~~~~~~~~
7070

71+
-
72+
7173
Categorical
7274
^^^^^^^^^^^
7375

pandas/core/frame.py

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

46214621
if self.empty:
4622-
return Series()
4622+
return Series(dtype=bool)
46234623

46244624
def f(vals):
46254625
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)