tabsdata.tableframe.lazyframe.frame.TableFrame.assert_has_cols#

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

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)