Skip to content

Commit bf4bdde

Browse files
committed
fix(set ops): raise if no tables passed to set operations
1 parent 30157c5 commit bf4bdde

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

ibis/backends/tests/test_set_ops.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pytest import param
44

55
import ibis
6+
import ibis.common.exceptions as com
67
from ibis import _
78

89

@@ -125,3 +126,9 @@ def test_difference(backend, alltypes, df, distinct):
125126
expected = expected.drop_duplicates()
126127

127128
backend.assert_frame_equal(result, expected)
129+
130+
131+
@pytest.mark.parametrize("method", ["intersect", "difference", "union"])
132+
def test_empty_set_op(backend, alltypes, method):
133+
with pytest.raises(com.IbisTypeError, match="requires a table or tables"):
134+
getattr(alltypes, method)()

ibis/expr/types/relations.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ def difference(self, *tables: Table, distinct: bool = True) -> Table:
349349
The rows present in `self` that are not present in `tables`.
350350
"""
351351
left = self
352+
if not tables:
353+
raise com.IbisTypeError(
354+
"difference requires a table or tables to compare against"
355+
)
352356
for right in tables:
353357
left = ops.Difference(left, right, distinct=distinct)
354358
return left.to_expr()
@@ -493,6 +497,10 @@ def union(self, *tables: Table, distinct: bool = False) -> Table:
493497
A new table containing the union of all input tables.
494498
"""
495499
left = self
500+
if not tables:
501+
raise com.IbisTypeError(
502+
"union requires a table or tables to compare against"
503+
)
496504
for right in tables:
497505
left = ops.Union(left, right, distinct=distinct)
498506
return left.to_expr()
@@ -515,6 +523,10 @@ def intersect(self, *tables: Table, distinct: bool = True) -> Table:
515523
A new table containing the intersection of all input tables.
516524
"""
517525
left = self
526+
if not tables:
527+
raise com.IbisTypeError(
528+
"intersect requires a table or tables to compare against"
529+
)
518530
for right in tables:
519531
left = ops.Intersection(left, right, distinct=distinct)
520532
return left.to_expr()

0 commit comments

Comments
 (0)