Skip to content

Commit 19296f1

Browse files
author
Giacomo Ferroni
committed
Added test for gh15077 (cf. gh15115) and whatsnew note
1 parent ea11867 commit 19296f1

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,4 @@ Bug Fixes
362362

363363

364364
- Bug in ``pd.read_csv()`` for the C engine where ``usecols`` were being indexed incorrectly with ``parse_dates`` (:issue:`14792`)
365+
- Bug in dtypes returned by comparison methods (e.g., ``lt``, ``gt``, ...) against a constant for an empty DataFrame (:issue:`15077`)

pandas/tests/frame/test_operators.py

+22
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,28 @@ def _test_seq(df, idx_ser, col_ser):
671671
exp = DataFrame({'col': [False, True, False]})
672672
assert_frame_equal(result, exp)
673673

674+
def test_return_dtypes_bool_op_costant(self):
675+
# GH15077
676+
df = DataFrame({'x': [1, 2, 3], 'y': [1., 2., 3.]})
677+
const = 2
678+
679+
# not empty DataFrame
680+
for op in ['eq', 'ne', 'gt', 'lt', 'ge', 'le']:
681+
f = getattr(df, op)
682+
for col in ['x', 'y']:
683+
res = f(const)
684+
c = getattr(res, col)
685+
self.assertEqual(c.dtypes, bool)
686+
687+
# empty DataFrame
688+
empty = df.iloc[:0]
689+
for op in ['eq', 'ne', 'gt', 'lt', 'ge', 'le']:
690+
f = getattr(empty, op)
691+
for col in ['x', 'y']:
692+
res = f(const)
693+
c = getattr(res, col)
694+
self.assertEqual(c.dtypes, bool)
695+
674696
def test_dti_tz_convert_to_utc(self):
675697
base = pd.DatetimeIndex(['2011-01-01', '2011-01-02',
676698
'2011-01-03'], tz='UTC')

0 commit comments

Comments
 (0)