Tableframe

TableFrame.assert_has_cols(
cols: str | list[str],
exact: bool | None = False,
) None
Categories:

tableframe

Ensures that the (non-system) columns in the TableFrame match the expected columns.

Raises an exception if the expectation is not met.

If exact is True, the check verifies that the TableFrame contains exactly the expected columns, with no extra or missing ones.

Parameters:
  • cols – The expected column name(s). Can be a string or a list of strings.

  • exact – If True, checks that the TableFrame contains exactly the specified columns.

Raises:

ValueError – If expected columns are missing or unexpected columns are present in the TableFrame.

Example:

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>> tf.assert_has_cols("a")
>>> tf.assert_has_cols(["a", "b"], exact=True)
TableFrame.clear(
n: int = 0,
) TableFrame
Categories:

tableframe

Clears all rows of the TableFrame preserving the schema.

Example:

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ a    ┆ b    │
│ ---  ┆ ---  │
│ str  ┆ i64  │
╞══════╪══════╡
│ A    ┆ 1    │
│ X    ┆ 10   │
│ C    ┆ 3    │
│ D    ┆ 5    │
│ M    ┆ 9    │
│ A    ┆ 100  │
│ M    ┆ 50   │
│ null ┆ 20   │
│ F    ┆ null │
└──────┴──────┘
>>>
>>> tf.cast({"b":td.Float32}).collect()
>>>
┌──────┬───────┐
│ a    ┆ b     │
│ ---  ┆ ---   │
│ str  ┆ f32   │
╞══════╪═══════╡
└──────┴───────┘
classmethod TableFrame.empty(
schema: SimpleSchema = None,
) TableFrame
Categories:

tableframe

Creates an empty (no column - no row) TableFrame.

classmethod TableFrame.from_dict(
data: Mapping[str, Sequence[object] | Mapping[str, Sequence[object]]] | None = None,
) TableFrame
Categories:

tableframe

Creates tableframe from a dictionary, or None. None produces as an empty (no column - no row) tableframe.

Parameters:

data – Input data.

classmethod TableFrame.from_pandas(
data: pd.DataFrame | None = None,
) TableFrame
Categories:

tableframe

Creates tableframe from a pandas dataframe, or None. None produces as an empty (no column - no row) tableframe.

Parameters:

data – Input data.

classmethod TableFrame.from_polars(
data: LazyFrame | DataFrame | None = None,
) TableFrame
Categories:

tableframe

Creates tableframe from a polars dataframe or lazyframe, or None. None produces as an empty (no column - no row) tableframe.

Parameters:

data – Input data.

TableFrame.has_cols(
cols: str | list[str],
exact: bool | None = False,
) Tuple[bool, set[str], set[str]]
Categories:

tableframe

Verifies the presence of (non-system) columns in the TableFrame.

If exact is True, the check ensures that the TableFrame contains exactly the specified columns (excluding system columns), with no extras or omissions.

Parameters:
  • cols – The column name(s) to verify. Can be a string or a list of strings.

  • exact – If True, checks that the TableFrame contains exactly the specified columns.

Returns:

  • A boolean indicating whether the check was successful.

  • A set of columns in cols missing in the TableFrame.

  • A set of columns in the TableFrame missing in cols.

Return type:

tuple[bool, set[str], set[str]]

Example:

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ a    ┆ b    │
│ ---  ┆ ---  │
│ str  ┆ i64  │
╞══════╪══════╡
│ A    ┆ 1    │
└──────┴──────┘
>>>
>>> tf.has_cols("a")
>>>
(True, {}, {"b"})
>>>
>>> tf.has_cols(["a", "c", "d"])
>>>
(False, {"c", "d"}, {"b"})
>>>
>>> tf.has_cols("a", exact=True)
>>>
(False, {}, {"b"})
>>>
>>> tf.has_cols(["a", "b"], exact=True)
>>>
(True, {}, {})
TableFrame.has_same_schema(
tf: TableFrame,
) bool
Categories:

tableframe

Categories:

description

Categories:

description

Verifies if the schema of the current TableFrame is same than the provided TableFrame.

Parameters:

tf – The TableFrame to compare with.

Returns:

Whether the condition is met or not.

Return type:

bool

Example:

>>> import tabsdata as td
>>>
>>> tf1: td.TableFrame ...
>>>
┌──────┬──────┐
│ a    ┆ b    │
│ ---  ┆ ---  │
│ str  ┆ i64  │
╞══════╪══════╡
│ A    ┆ 1    │
└──────┴──────┘
>>>
>>> tf2: td.TableFrame ...
>>>
┌──────┬──────┐
│ a    ┆ c    │
│ ---  ┆ ---  │
│ str  ┆ i64  │
╞══════╪══════╡
│ A    ┆ 1    │
└──────┴──────┘
>>> tf1.has_same_schema(tf2)
>>>
False
>>>
>>> tf1: td.TableFrame ...
>>>
┌──────┬──────┐
│ a    ┆ b    │
│ ---  ┆ ---  │
│ str  ┆ i64  │
╞══════╪══════╡
│ A    ┆ 1    │
└──────┴──────┘
>>>
>>> tf2: td.TableFrame ...
>>>
┌──────┬──────┐
│ a    ┆ b    │
│ ---  ┆ ---  │
│ str  ┆ str  │
╞══════╪══════╡
│ A    ┆ 1    │
└──────┴──────┘
>>> tf1.has_same_schema(tf2)
>>>
False
TableFrame.is_empty() bool
Categories:

tableframe

Checks if a TableFrame has no rows.

Example:

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ a    ┆ b    │
│ ---  ┆ ---  │
│ str  ┆ i64  │
╞══════╪══════╡
│ A    ┆ 1    │
└──────┴──────┘
>>>
>>> tf.is_empty()
>>>
False
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ a    ┆ b    │
│ ---  ┆ ---  │
│ str  ┆ i64  │
╞══════╪══════╡
└──────┴──────┘
>>>
>>> tf.is_empty()
>>>
True
TableFrame.sort(
by: td_typing.IntoExpr | Iterable[td_typing.IntoExpr],
*more_by: td_typing.IntoExpr,
descending: bool | Sequence[bool] = False,
nulls_last: bool | Sequence[bool] = False,
maintain_order: bool = False,
) TableFrame
Categories:

tableframe

Sort the TableFrame by the given column(s) or expression(s).

Parameters:
  • by – Column(s) or expression(s) to sort by.

  • more_by – Additional colums to sort by.

  • descending – Specifies if the sorting should be descending or not.

  • nulls_last – Specifies if null values should be placed last.

  • maintain_order – Preserve the order of equal rows.

Example:

>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ a    ┆ b    │
│ ---  ┆ ---  │
│ str  ┆ i64  │
╞══════╪══════╡
│ A    ┆ 1    │
│ X    ┆ 10   │
│ C    ┆ 3    │
│ D    ┆ 5    │
│ M    ┆ 9    │
│ A    ┆ 100  │
│ M    ┆ 50   │
│ null ┆ 20   │
│ F    ┆ null │
└──────┴──────┘
>>>
>>> tf.sort(td.col("a"), descending = True)
>>>
┌──────┬───────┐
│ a    ┆ b     │
│ ---  ┆ ---   │
│ str  ┆ f32   │
╞══════╪═══════╡
│ A    ┆ 1.0   │
│ X    ┆ 10.0  │
│ C    ┆ 3.0   │
│ D    ┆ 5.0   │
│ M    ┆ 9.0   │
│ A    ┆ 100.0 │
│ M    ┆ 50.0  │
│ null ┆ 20.0  │
│ F    ┆ null  │
└──────┴───────┘
TableFrame.to_dict() dict[str, list[Any]]
Categories:

tableframe

Creates a dictionary from this tableframe.

TableFrame.to_pandas() pd.DataFrame
Categories:

tableframe

Creates a pandas dataframe from this tableframe.

TableFrame.to_polars_df() DataFrame
Categories:

tableframe

Creates a polars dataframe from this tableframe.

TableFrame.to_polars_lf() LazyFrame
Categories:

tableframe

Creates a polars lazyframe from this tableframe.