TableValidator#
- class tollan.utils.table.TableValidator[source]#
Bases:
objectValidator 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
colsthat 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
keysthat 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
colsthat exist in the table.validate_meta(meta, keys)Return the subset of keys in
keysthat 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).
- get_first_col(tbl: Table | QTable | DataFrame, cols: list[str]) str | None[source]#
Return the first column in
colsthat exists in the table, or None.
- get_first_col_data(tbl: Table | QTable | DataFrame, cols: list[str]) Any | None[source]#
Return data from the first column in
cols.
- get_first_meta(meta: dict, keys: list[str]) str | None[source]#
Return the first key in
keysthat exists in the metadata dict, or None.
- get_first_meta_value(meta: dict, keys: list[str]) Any | None[source]#
Return the value for the first key in
keys.
- 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).
- has_all_cols(tbl: Table | QTable | DataFrame, cols: list[str]) bool[source]#
Return True if all specified columns exist in the table.
- has_all_meta(meta: dict, keys: list[str]) bool[source]#
Return True if all specified keys exist in the metadata dict.
- has_any_col(tbl: Table | QTable | DataFrame, cols: list[str]) bool[source]#
Return True if any of the specified columns exist in the table.
- has_any_meta(meta: dict, keys: list[str]) bool[source]#
Return True if any of the specified keys exist in the metadata dict.
- 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