Skip to content

temporian.from_polars #

    df: polars.DataFrame,
    indexes: Optional[List[str]] = None,
    timestamps: str = "timestamp",
    name: Optional[str] = None,
    same_sampling_as: Optional[EventSet] = None,
    allow_copy: bool = True,
) -> EventSet

Converts a Polars DataFrame into an EventSet.

See tp.event_set() for the list of supported timestamp and feature types.

The allow_copy parameter is passed directly to Polars' to_numpy method. If set to False, the conversion process may fail if Polars is unable to perform a zero-copy conversion.Users are encouraged to refer to Polars documentation on to_numpy for detailed information on when a non-zero-copy conversion might be required.


The function attempts to minimize data copying but will copy if required for compatibility.

Usage example
>>> import polars as pl
>>> df = pl.DataFrame(
...       {
...            "product_id": [666964, 666964, 574016, 574016],
...            "timestamp": [1.0, 2.0, 3.0, 4.0],
...            "costs": [740.0, 508.0, 573.0, None],
...        }
...    )
>>> evset = tp.from_polars(df, indexes=["product_id"])

>>> df1 = pl.DataFrame(
...        {
...            "timestamp": [1, 2, 3, 4],
...            "id": [1, 2, 3, None],
...            "category": [10, 20, 30, 40]
...        }
...    )

# allow_copy=False will result in zero_copy error for the below event set.
>>> evset1 = tp.from_polars(df1, indexes=["category"], allow_copy=True)


Name Type Description Default
df DataFrame

A non indexed Polars dataframe.

indexes Optional[List[str]]

Names of the columns to use as indexes. If empty (default), the data is not indexed. Only integer and string columns can be used as indexes.

timestamps str

Name of the column containing the timestamps. See tp.event_set() for the list of supported timestamp types.

name Optional[str]

Optional name of the EventSet. Used for debugging, and graph serialization.

same_sampling_as Optional[EventSet]

If set, the new EventSet is checked and tagged as having the same sampling as same_sampling_as. Some operators, such as EventSet.filter(), require their inputs to have the same sampling.

allow_copy bool

Allow memory to be copied to perform the conversion. If set to False, causes conversions that are not zero-copy to fail.


Returns: An EventSet.