Skip to content

QuokkaContext.from_polars

Create a DataStream from a polars DataFrame. The DataFrame will be materialized. If you don't know what this means, don't worry about it.

Parameters:

Name Type Description Default
df Polars DataFrame

The polars DataFrame to create the DataStream from.

required

Returns:

Name Type Description
DataStream

The DataStream created from the polars DataFrame.

Examples:

>>> import polars as pl
>>> from pyquokka.df import QuokkaContext
>>> qc = QuokkaContext()
>>> df = pl.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
>>> stream = qc.from_polars(df)
>>> stream.count()
Source code in pyquokka/df.py
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
def from_polars(self, df):

    """
    Create a DataStream from a polars DataFrame. The DataFrame will be materialized. If you don't know what this means, don't worry about it.

    Args:
        df (Polars DataFrame): The polars DataFrame to create the DataStream from.

    Returns:
        DataStream: The DataStream created from the polars DataFrame.

    Examples:

        >>> import polars as pl
        >>> from pyquokka.df import QuokkaContext
        >>> qc = QuokkaContext()
        >>> df = pl.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
        >>> stream = qc.from_polars(df)
        >>> stream.count()
    """

    self.nodes[self.latest_node_id] = InputPolarsNode(df)
    self.latest_node_id += 1
    return DataStream(self, df.columns, self.latest_node_id - 1, materialized=True)