Skip to content

Commit c198e28

Browse files
authored
BUG: DataFrame.isin empty datetimelike (#15570)
1 parent 0b77680 commit c198e28

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

doc/source/whatsnew/v0.20.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ Bug Fixes
677677
- Bug in ``pd.read_msgpack()`` in which ``Series`` categoricals were being improperly processed (:issue:`14901`)
678678
- Bug in ``Series.ffill()`` with mixed dtypes containing tz-aware datetimes. (:issue:`14956`)
679679

680-
680+
- Bug in ``DataFrame.isin`` comparing datetimelike to empty frame (:issue:`15473`)
681681

682682
- Bug in ``Series.where()`` and ``DataFrame.where()`` where array-like conditionals were being rejected (:issue:`15414`)
683683
- Bug in ``Series`` construction with a datetimetz (:issue:`14928`)

pandas/core/ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ def na_op(x, y):
12491249
result = op(x, y)
12501250
except TypeError:
12511251
xrav = x.ravel()
1252-
result = np.empty(x.size, dtype=x.dtype)
1252+
result = np.empty(x.size, dtype=bool)
12531253
if isinstance(y, (np.ndarray, ABCSeries)):
12541254
yrav = y.ravel()
12551255
mask = notnull(xrav) & notnull(yrav)

pandas/tests/frame/test_analytics.py

+21
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,27 @@ def test_isin_multiIndex(self):
15021502
result = df1.isin(df2)
15031503
tm.assert_frame_equal(result, expected)
15041504

1505+
def test_isin_empty_datetimelike(self):
1506+
# GH 15473
1507+
df1_ts = DataFrame({'date':
1508+
pd.to_datetime(['2014-01-01', '2014-01-02'])})
1509+
df1_td = DataFrame({'date':
1510+
[pd.Timedelta(1, 's'), pd.Timedelta(2, 's')]})
1511+
df2 = DataFrame({'date': []})
1512+
df3 = DataFrame()
1513+
1514+
expected = DataFrame({'date': [False, False]})
1515+
1516+
result = df1_ts.isin(df2)
1517+
tm.assert_frame_equal(result, expected)
1518+
result = df1_ts.isin(df3)
1519+
tm.assert_frame_equal(result, expected)
1520+
1521+
result = df1_td.isin(df2)
1522+
tm.assert_frame_equal(result, expected)
1523+
result = df1_td.isin(df3)
1524+
tm.assert_frame_equal(result, expected)
1525+
15051526
# ----------------------------------------------------------------------
15061527
# Row deduplication
15071528

0 commit comments

Comments
 (0)