Build a table from columns. All columns must have the same ids. Columns' names must be pairwise distinct. Args: args: List of columns. kwargs: Columns with their new names. Returns: Table: Created table. Example: >>> i
(
*args: expr.ColumnReference, **kwargs: expr.ColumnReference
)
| 270 | @staticmethod |
| 271 | @check_arg_types |
| 272 | def from_columns( |
| 273 | *args: expr.ColumnReference, **kwargs: expr.ColumnReference |
| 274 | ) -> Table: |
| 275 | """Build a table from columns. |
| 276 | |
| 277 | All columns must have the same ids. Columns' names must be pairwise distinct. |
| 278 | |
| 279 | Args: |
| 280 | args: List of columns. |
| 281 | kwargs: Columns with their new names. |
| 282 | |
| 283 | Returns: |
| 284 | Table: Created table. |
| 285 | |
| 286 | |
| 287 | Example: |
| 288 | |
| 289 | >>> import pathway as pw |
| 290 | >>> t1 = pw.Table.empty(age=float, pet=float) |
| 291 | >>> t2 = pw.Table.empty(foo=float, bar=float).with_universe_of(t1) |
| 292 | >>> t3 = pw.Table.from_columns(t1.pet, qux=t2.foo) |
| 293 | >>> pw.debug.compute_and_print(t3, include_id=False) |
| 294 | pet | qux |
| 295 | """ |
| 296 | all_args = cast( |
| 297 | dict[str, expr.ColumnReference], combine_args_kwargs(args, kwargs) |
| 298 | ) |
| 299 | if not all_args: |
| 300 | raise ValueError("Table.from_columns() cannot have empty arguments list") |
| 301 | else: |
| 302 | arg = next(iter(all_args.values())) |
| 303 | table: Table = arg.table |
| 304 | for arg in all_args.values(): |
| 305 | if not table._universe.is_equal_to(arg.table._universe): |
| 306 | raise ValueError( |
| 307 | "Universes of all arguments of Table.from_columns() have to be equal.\n" |
| 308 | + "Consider using Table.promise_universes_are_equal() to assert it.\n" |
| 309 | + "(However, untrue assertion might result in runtime errors.)" |
| 310 | ) |
| 311 | return table.select(*args, **kwargs) |
| 312 | |
| 313 | @trace_user_frame |
| 314 | @check_arg_types |