traveler.tables.read_table#

traveler.tables.read_table(filepath, columns=None, *, sample=None, seed=42, format=None, consolidate=True)[source]#

Read a table from a file and return its column definitions.

Parameters:
  • filepath (str or os.PathLike) – The path to the file containing the table.

  • columns (dict[str, str | pl.Expr | Sequence[str]], optional) –

    A dictionary mapping final column names to their definitions. If None, all columns in the source file are included with their original names. If given, each key is the final column name, and each value can be:

    • A string: the name of the column in the source file, which may or may not be the same as the final column name.

    • A pl.Expr: a Polars expression to define the column.

    • A Sequence of strings: a list of possible column names to try, in order.

    If a column is not found in the source file, an error is raised.

  • sample (int, optional) – The number of rows to sample from the table. If None, no sampling is done.

  • seed (int, optional) – The random seed to use for sampling. Default is 42.

  • format (type, optional) – The class type to use for the table. If provided, the columns will be cast to the types defined in the class annotations.

  • consolidate (bool, optional) – If True, the DataFrame columns will be consolidated into a single chunk of memory. This is useful for performance reasons, allowing zero-copy operations to the JAX tools. Default is True.

Return type:

polars.DataFrame