tabsdata.tableframe
Column | Represents a single column definition in a :class:TableFrame. |
concat | Combine multiple TableFrames by stacking their rows. |
empty | Creates an empty (no column - no row) TableFrame. |
from_dict | Creates tableframe from a dictionary, or None. |
from_pandas | Creates tableframe from a pandas dataframe, or None. |
from_polars | Creates tableframe from a polars dataframe or lazyframe, or None. |
lit | Expression for the given literal value. |
Schema | |
TableFrame | > Private Functions |
TableFrame.assert_has_cols | Ensures that the (non-system) columns in the TableFrame match the expected columns. |
TableFrame.cast | Cast columns to a new data type. |
TableFrame.clear | Clears all rows of the TableFrame preserving the schema. |
TableFrame.columns | |
TableFrame.drop | Discard columns from the TableFrame. |
TableFrame.drop_nans | Drop rows with NaN values. |
TableFrame.drop_nulls | Drop rows with null values. |
TableFrame.empty | Creates an empty (no column - no row) TableFrame. |
TableFrame.extract_as_columns | Extract a slice of rows from the table as a column-oriented dictionary. |
TableFrame.extract_as_rows | Extract a slice of rows from the TableFrame as a list of dictionaries. |
TableFrame.fill_nan | Replace all NaN values in the TableFrame with the given value. |
TableFrame.fill_null | Replace all null values in the TableFrame with the given value. |
TableFrame.filter | Filter the TableFrame based on the given predicates. |
TableFrame.first | Return a TableFrame with the first row. |
TableFrame.first_row | Return a tuple or dictionary with the first row, or None if no row. |
TableFrame.from_dict | Creates tableframe from a dictionary, or None. |
TableFrame.from_pandas | Creates tableframe from a pandas dataframe, or None. |
TableFrame.from_polars | Creates tableframe from a polars dataframe or lazyframe, or None. |
TableFrame.grok | Parse log text into structured fields using a Grok pattern. |
TableFrame.group_by | Perform a group by on the TableFrame. |
TableFrame.has_cols | Verifies the presence of (non-system) columns in the TableFrame. |
TableFrame.has_same_schema | Verifies if the schema of the current TableFrame is same than the provided TableFrame. |
TableFrame.head | Return a TableFrame with the first n rows. |
TableFrame.is_empty | Checks if a TableFrame has no rows. |
TableFrame.item | Returns a scalar value if the TableFrame contains exactly one user column and one row. |
TableFrame.join | Join the TableFrame with another TableFrame. |
TableFrame.last | Return a TableFrame with the last row. |
TableFrame.last_row | Return a tuple or dictionary with the last row, or None if no row. |
TableFrame.limit | Return a TableFrame with the first n rows. |
TableFrame.rename | Rename columns from the TableFrame. |
TableFrame.select | Select column(s) from the TableFrame. |
TableFrame.slice | Return a TableFrame with a slice of the original TableFrame |
TableFrame.sort | Sort the TableFrame by the given column(s) or expression(s). |
TableFrame.tail | Return a TableFrame with the last n rows. |
TableFrame.to_dict | Creates a dictionary from this tableframe. |
TableFrame.to_pandas | Creates a pandas dataframe from this tableframe. |
TableFrame.to_polars_df | Creates a polars dataframe from this tableframe. |
TableFrame.to_polars_lf | Creates a polars lazyframe from this tableframe. |
TableFrame.udf | Apply a user-defined function (UDF) to the columns resolved by expr. |
TableFrame.unique | Deduplicate rows from the TableFrame. |
TableFrame.unnest | Expand one or more struct columns so that each field within the struct becomes a separate column in the TableFrame. |
TableFrame.with_columns | Add columns to the TableFrame. |
to_dict | Creates dictionary from a tableframe, or None. |
to_pandas | Creates pandas dataframe from a tableframe, or None. |
to_polars_df | Creates polars dataframe from a tableframe, or None. |
to_polars_lf | Creates polars lazyframe from a tableframe, or None. |
UDF | |
UDF.columns | |
UDF.on_batch | Creating UDFs: 1. |
UDF.on_element | Creating UDFs: 1. |
UDF.with_columns |
Column
class Column(name: str | None = None, dtype: td_DataType = String)
Represents a single column definition in a :class:TableFrame.
A Column defines both the name and the data type of a column,
along with other relevant metadata in the future. This abstraction provides
a consistent way to declare and validate schema definitions for TableFrame
objects.
Attributes:
namestr | NoneThe name of the column, or None if no name was provided.
dtypetd_DataTypeThe declared data type of the column.
Example:
Create a column with a name and type:
>>> import tabsdata as td
>>> Column("customer_id", td.Int64)
<Column name='customer_id' dtype=Int64>
Use columns to define a TableFrame schema:
>>> import tabsdata as td
>>> schema = [
... Column("customer_id", td.Int64),
... Column("signup_date", td.Datetime),
... ]
>>> for column in schema:
... print(column.name, column.dtype)
customer_id Int64
signup_date Datetime
empty
def empty() -> TableFrame
Creates an empty (no column - no row) TableFrame.
from_dict
def from_dict(data: td_TableDictionary | None = None) -> TableFrame
Creates tableframe from a dictionary, or None.
None produces as an empty (no column - no row) tableframe.
Parameters:
dataInput data.
from_pandas
def from_pandas(data: DataFrame | None = None) -> TableFrame
Creates tableframe from a pandas dataframe, or None.
None produces as an empty (no column - no row) tableframe.
Parameters:
dataInput data.
from_polars
def from_polars(data: LazyFrame | DataFrame | None = None) -> TableFrame
Creates tableframe from a polars dataframe or lazyframe, or None.
None produces as an empty (no column - no row) tableframe.
Parameters:
dataInput data.
Schema
class Schema(
schema: Iterable[Column] | Mapping[str, td_SchemaInitDataType] | Iterable[tuple[str, td_SchemaInitDataType] | td_ArrowSchemaExportable] | td_ArrowSchemaExportable | None = None,
check_dtypes: bool = True,
)
Bases: Schema
to_dict
def to_dict(data: TableFrame) -> dict[str, list[Any]]
Creates dictionary from a tableframe, or None.
None produces and empty (no key) dictionary.
Parameters:
dataInput data.
to_pandas
def to_pandas(data: TableFrame) -> DataFrame
Creates pandas dataframe from a tableframe, or None.
None produces and empty (no column - no row) pandas dataframe.
Parameters:
dataInput data.
to_polars_df
def to_polars_df(data: TableFrame) -> DataFrame
Creates polars dataframe from a tableframe, or None.
None produces and empty (no column - no row) polars dataframe.
Parameters:
dataInput data.
to_polars_lf
def to_polars_lf(data: TableFrame) -> LazyFrame
Creates polars lazyframe from a tableframe, or None.
None produces and empty (no column - no row) polars lazyframe.
Parameters:
dataInput data.
UDF
class UDF(
output_columns: list[tuple[str, DataTypeClass | DataType]] | tuple[str, DataTypeClass | DataType],
)
Bases: ABC
on_batchdef on_batch(series: list[Series]) -> list[Series]
Creating UDFs:
- Subclass :class:
tabsdata.tableframe.udf.function.UDF. - Implement
__init__to callsuper().__init__(output_columns)whereoutput_columnsis a tuple or list of tuples(name, data type)specifying the UDF default output schema (column names and data types). Each tuple must contain a column name (string) and a data type (DataType). - Override exactly one of
on_batchoron_element, to implement the UDF function logic. - Return a list of TabsData Series (for
on_batch) or TabsData supported scalars (foron_element) with the same length as specified in the output schema. - If overriding the
on_batchmethod, the return type must be a list of TabsData Series. If overriding theon_elementmethod, the return type must be a list of supported TabsData scalar values. For both cases, the number of elements in the returned lists must match the number of elements in the output_columns list provided to the UDF constructor.
Using UDFs:
- Instantiate a function created as above.
- Pass it to TableFrame method udf().
- Optionally use :meth:
UDF.output_columnsto override output column names or data types after instantiation.
on_elementdef on_element(values: list[Any]) -> list[Any]
Creating UDFs:
- Subclass :class:
tabsdata.tableframe.udf.function.UDF. - Implement
__init__to callsuper().__init__(output_columns)whereoutput_columnsis a tuple or list of tuples(name, data type)specifying the UDF default output schema (column names and data types). Each tuple must contain a column name (string) and a data type (DataType). - Override exactly one of
on_batchoron_element, to implement the UDF function logic. - Return a list of TabsData Series (for
on_batch) or TabsData supported scalars (foron_element) with the same length as specified in the output schema. - If overriding the
on_batchmethod, the return type must be a list of TabsData Series. If overriding theon_elementmethod, the return type must be a list of supported TabsData scalar values. For both cases, the number of elements in the returned lists must match the number of elements in the output_columns list provided to the UDF constructor.
Using UDFs:
- Instantiate a function created as above.
- Pass it to TableFrame method udf().
- Optionally use :meth:
UDF.output_columnsto override output column names or data types after instantiation.
with_columnsdef with_columns(
output_columns: tuple[str | None, DataTypeClass | DataType | NoneType] | list[tuple[str | None, DataTypeClass | DataType | NoneType]] | dict[int, tuple[str | None, DataTypeClass | DataType | NoneType]],
) -> UDF