TableValidator#

class tollan.utils.table.TableValidator[source]#

Bases: object

Validator for astropy and pandas tables.

Provides a unified interface for column and metadata validation across astropy Table/QTable and pandas DataFrame objects.

Methods Summary

eval(tbl, expr, **kwargs)

Evaluate an expression on table columns.

get_col_data(tbl, cols)

Return a list of data for each column in cols (None if missing).

get_first_col(tbl, cols)

Return the first column in cols that exists in the table, or None.

get_first_col_data(tbl, cols)

Return data from the first column in cols.

get_first_meta(meta, keys)

Return the first key in keys that exists in the metadata dict, or None.

get_first_meta_value(meta, keys)

Return the value for the first key in keys.

get_meta_values(meta, keys)

Return a list of values for each key in keys (None if missing).

has_all_cols(tbl, cols)

Return True if all specified columns exist in the table.

has_all_meta(meta, keys)

Return True if all specified keys exist in the metadata dict.

has_any_col(tbl, cols)

Return True if any of the specified columns exist in the table.

has_any_meta(meta, keys)

Return True if any of the specified keys exist in the metadata dict.

query()

Return a filtered table using a query expression.

validate_cols(tbl, cols)

Return the subset of columns in cols that exist in the table.

validate_meta(meta, keys)

Return the subset of keys in keys that exist in the metadata dict.

Methods Documentation

eval(tbl: Table | QTable | DataFrame, expr: str, **kwargs: Any) Any[source]#

Evaluate an expression on table columns.

Parameters:
  • tbl (TableT) – Table to evaluate expression on

  • expr (str) – Expression to evaluate (column names available as variables)

  • **kwargs – Additional arguments passed to pd.eval or DataFrame.eval

Returns:

Result of expression evaluation

Return type:

Any

get_col_data(tbl: Table | QTable | DataFrame, cols: list[str]) list[Any | None][source]#

Return a list of data for each column in cols (None if missing).

Parameters:
  • tbl (TableT) – Table to retrieve data from

  • cols (list[str]) – Column names to retrieve

Returns:

List of column data (None for missing columns)

Return type:

list[Any | None]

get_first_col(tbl: Table | QTable | DataFrame, cols: list[str]) str | None[source]#

Return the first column in cols that exists in the table, or None.

Parameters:
  • tbl (TableT) – Table to search

  • cols (list[str]) – Column names to search for

Returns:

First matching column name, or None if no match

Return type:

str | None

get_first_col_data(tbl: Table | QTable | DataFrame, cols: list[str]) Any | None[source]#

Return data from the first column in cols.

Parameters:
  • tbl (TableT) – Table to retrieve data from

  • cols (list[str]) – Column names to search for

Returns:

Column data from first match, or None if no match

Return type:

Any | None

get_first_meta(meta: dict, keys: list[str]) str | None[source]#

Return the first key in keys that exists in the metadata dict, or None.

Parameters:
  • meta (dict) – Metadata dictionary to search

  • keys (list[str]) – Keys to search for

Returns:

First matching key, or None if no match

Return type:

str | None

get_first_meta_value(meta: dict, keys: list[str]) Any | None[source]#

Return the value for the first key in keys.

Parameters:
  • meta (dict) – Metadata dictionary to retrieve from

  • keys (list[str]) – Keys to search for

Returns:

Value for first matching key, or None if no match

Return type:

Any | None

get_meta_values(meta: dict, keys: list[str]) list[Any | None][source]#

Return a list of values for each key in keys (None if missing).

Parameters:
  • meta (dict) – Metadata dictionary to retrieve from

  • keys (list[str]) – Keys to retrieve values for

Returns:

List of values (None for missing keys)

Return type:

list[Any | None]

has_all_cols(tbl: Table | QTable | DataFrame, cols: list[str]) bool[source]#

Return True if all specified columns exist in the table.

Parameters:
  • tbl (TableT) – Table to check

  • cols (list[str]) – Column names to search for

Returns:

True if all columns in cols exist in table

Return type:

bool

has_all_meta(meta: dict, keys: list[str]) bool[source]#

Return True if all specified keys exist in the metadata dict.

Parameters:
  • meta (dict) – Metadata dictionary to check

  • keys (list[str]) – Keys to search for

Returns:

True if all keys exist in meta

Return type:

bool

has_any_col(tbl: Table | QTable | DataFrame, cols: list[str]) bool[source]#

Return True if any of the specified columns exist in the table.

Parameters:
  • tbl (TableT) – Table to check

  • cols (list[str]) – Column names to search for

Returns:

True if any column in cols exists in table

Return type:

bool

has_any_meta(meta: dict, keys: list[str]) bool[source]#

Return True if any of the specified keys exist in the metadata dict.

Parameters:
  • meta (dict) – Metadata dictionary to check

  • keys (list[str]) – Keys to search for

Returns:

True if any key exists in meta

Return type:

bool

query(tbl: DataFrame, expr: str, **kwargs: Any) DataFrame[source]#
query(tbl: Table | QTable, expr: str, **kwargs: Any) Table | QTable

Return a filtered table using a query expression.

Parameters:
  • tbl (TableT) – Table to filter

  • expr (str) – Boolean expression for filtering rows

  • **kwargs – Additional arguments passed to query evaluation

Returns:

Filtered table with rows matching expression

Return type:

TableT

validate_cols(tbl: Table | QTable | DataFrame, cols: list[str]) list[str][source]#

Return the subset of columns in cols that exist in the table.

Parameters:
  • tbl (TableT) – Table to validate.

  • cols (list[str]) – Column names to check.

Returns:

Subset of cols that exist in tbl.

Return type:

list[str]

validate_meta(meta: dict, keys: list[str]) list[str][source]#

Return the subset of keys in keys that exist in the metadata dict.

Parameters:
  • meta (dict) – Metadata dictionary to check

  • keys (list[str]) – Keys to search for

Returns:

Subset of keys that exist in meta

Return type:

list[str]