Skip to main content
Version: 1.2.0

TableFrame.has_cols

def has_cols(
cols: str | list[str],
exact: bool | None = False,
) -> (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

parameter
cols

The column name(s) to verify. Can be a string or a list of strings.

parameter
exact

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

Returns

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

  • 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.

Examples

>>> 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, {}, {})