@@ -760,6 +760,10 @@ def difference(self, *tables: Table, distinct: bool = True) -> Table:
760
760
distinct
761
761
Only diff distinct rows not occurring in the calling table
762
762
763
+ See Also
764
+ --------
765
+ [`ibis.difference`][ibis.difference]
766
+
763
767
Returns
764
768
-------
765
769
Table
@@ -797,15 +801,36 @@ def difference(self, *tables: Table, distinct: bool = True) -> Table:
797
801
├───────┤
798
802
│ 1 │
799
803
└───────┘
804
+
805
+ Passing no arguments to `difference` returns the table expression
806
+
807
+ This can be useful when you have a sequence of tables to process, and
808
+ you don't know the length prior to running your program (for example, user input).
809
+
810
+ >>> t1
811
+ ┏━━━━━━━┓
812
+ ┃ a ┃
813
+ ┡━━━━━━━┩
814
+ │ int64 │
815
+ ├───────┤
816
+ │ 1 │
817
+ │ 2 │
818
+ └───────┘
819
+ >>> t1.difference()
820
+ ┏━━━━━━━┓
821
+ ┃ a ┃
822
+ ┡━━━━━━━┩
823
+ │ int64 │
824
+ ├───────┤
825
+ │ 1 │
826
+ │ 2 │
827
+ └───────┘
828
+ >>> t1.difference().equals(t1)
829
+ True
800
830
"""
801
- left = self
802
- if not tables :
803
- raise com .IbisTypeError (
804
- "difference requires a table or tables to compare against"
805
- )
806
- for right in tables :
807
- left = ops .Difference (left , right , distinct = distinct )
808
- return left .to_expr ()
831
+ return functools .reduce (
832
+ functools .partial (ops .Difference , distinct = distinct ), tables , self .op ()
833
+ ).to_expr ()
809
834
810
835
def aggregate (
811
836
self ,
@@ -1102,6 +1127,10 @@ def union(self, *tables: Table, distinct: bool = False) -> Table:
1102
1127
Table
1103
1128
A new table containing the union of all input tables.
1104
1129
1130
+ See Also
1131
+ --------
1132
+ [`ibis.union`][ibis.union]
1133
+
1105
1134
Examples
1106
1135
--------
1107
1136
>>> import ibis
@@ -1147,15 +1176,36 @@ def union(self, *tables: Table, distinct: bool = False) -> Table:
1147
1176
│ 2 │
1148
1177
│ 3 │
1149
1178
└───────┘
1179
+
1180
+ Passing no arguments to `union` returns the table expression
1181
+
1182
+ This can be useful when you have a sequence of tables to process, and
1183
+ you don't know the length prior to running your program (for example, user input).
1184
+
1185
+ >>> t1
1186
+ ┏━━━━━━━┓
1187
+ ┃ a ┃
1188
+ ┡━━━━━━━┩
1189
+ │ int64 │
1190
+ ├───────┤
1191
+ │ 1 │
1192
+ │ 2 │
1193
+ └───────┘
1194
+ >>> t1.union()
1195
+ ┏━━━━━━━┓
1196
+ ┃ a ┃
1197
+ ┡━━━━━━━┩
1198
+ │ int64 │
1199
+ ├───────┤
1200
+ │ 1 │
1201
+ │ 2 │
1202
+ └───────┘
1203
+ >>> t1.union().equals(t1)
1204
+ True
1150
1205
"""
1151
- left = self
1152
- if not tables :
1153
- raise com .IbisTypeError (
1154
- "union requires a table or tables to compare against"
1155
- )
1156
- for right in tables :
1157
- left = ops .Union (left , right , distinct = distinct )
1158
- return left .to_expr ()
1206
+ return functools .reduce (
1207
+ functools .partial (ops .Union , distinct = distinct ), tables , self .op ()
1208
+ ).to_expr ()
1159
1209
1160
1210
def intersect (self , * tables : Table , distinct : bool = True ) -> Table :
1161
1211
"""Compute the set intersection of multiple table expressions.
@@ -1174,6 +1224,10 @@ def intersect(self, *tables: Table, distinct: bool = True) -> Table:
1174
1224
Table
1175
1225
A new table containing the intersection of all input tables.
1176
1226
1227
+ See Also
1228
+ --------
1229
+ [`ibis.intersect`][ibis.intersect]
1230
+
1177
1231
Examples
1178
1232
--------
1179
1233
>>> import ibis
@@ -1206,15 +1260,36 @@ def intersect(self, *tables: Table, distinct: bool = True) -> Table:
1206
1260
├───────┤
1207
1261
│ 2 │
1208
1262
└───────┘
1263
+
1264
+ Passing no arguments to `intersect` returns the table expression.
1265
+
1266
+ This can be useful when you have a sequence of tables to process, and
1267
+ you don't know the length prior to running your program (for example, user input).
1268
+
1269
+ >>> t1
1270
+ ┏━━━━━━━┓
1271
+ ┃ a ┃
1272
+ ┡━━━━━━━┩
1273
+ │ int64 │
1274
+ ├───────┤
1275
+ │ 1 │
1276
+ │ 2 │
1277
+ └───────┘
1278
+ >>> t1.intersect()
1279
+ ┏━━━━━━━┓
1280
+ ┃ a ┃
1281
+ ┡━━━━━━━┩
1282
+ │ int64 │
1283
+ ├───────┤
1284
+ │ 1 │
1285
+ │ 2 │
1286
+ └───────┘
1287
+ >>> t1.intersect().equals(t1)
1288
+ True
1209
1289
"""
1210
- left = self
1211
- if not tables :
1212
- raise com .IbisTypeError (
1213
- "intersect requires a table or tables to compare against"
1214
- )
1215
- for right in tables :
1216
- left = ops .Intersection (left , right , distinct = distinct )
1217
- return left .to_expr ()
1290
+ return functools .reduce (
1291
+ functools .partial (ops .Intersection , distinct = distinct ), tables , self .op ()
1292
+ ).to_expr ()
1218
1293
1219
1294
def to_array (self ) -> ir .Column :
1220
1295
"""View a single column table as an array.
0 commit comments