spacr.columns¶
Report missing columns and offer the columns that are available.
Without this check, a misnamed dependent_variable passes the early checks
and fails inside the merge, after the whole score table has been read, with a
message that names the missing column but not the available ones.
Three rules apply:
Only the header row is read (
nrows=0). The check runs before the run, sometimes to populate a GUI dropdown on the GUI thread, and a score CSV can be hundreds of megabytes.A missing file is reported separately from a missing column. A missing file has no header to compare against; a missing column is reported with the columns that do exist.
Suggestions are given in addition to the full column list. Near-misses are listed first because
predictionsforpredictionis a common typo, and the full list is always included as well.
Exceptions¶
Raised when a named column is absent; the message lists those present. |
Functions¶
|
Every column across |
|
Return the message to print or raise when column |
|
|
|
Return the paths whose header could not be read by |
|
|
|
The sentence that says where a |
|
The readable files among |
|
|
|
Column names close to |
Module Contents¶
- exception spacr.columns.ColumnNotFound(message: str, *, name: str = '', available: Sequence[str] = ())[source]¶
Bases:
KeyErrorRaised when a named column is absent; the message lists those present.
- Parameters:
message – human-readable explanation returned for the exception.
name – the column that was asked for, kept so a caller can recover it without parsing
message.available – the columns the file does have, in file order. Not sorted, because file order is what a user reading the header sees, and sorting hides that related columns are grouped together.
A KeyError subclass so existing
except KeyErrorpaths still catch it, and sosettings['x']failures and this one read the same way to a caller that does not care which it was.Initialize a readable error with structured column context.
- spacr.columns.available(paths) List[str][source]¶
Every column across
paths, in order, without duplicates.- Parameters:
paths – one CSV path, a sequence of paths, or None.
Across, not per file:
score_datais routinely a list of one CSV per plate with identical headers, and a user choosing a column does not care which plate it came from.
- spacr.columns.describe(name, paths, *, what: str = 'column', setting: str = '') str[source]¶
Return the message to print or raise when column
nameis missing.- Parameters:
name – missing column name to explain.
paths – CSV paths whose headers should be reported.
Names the setting, the files that were read, the near-misses and then every column.
- spacr.columns.headers(paths) Dict[str, List[str]][source]¶
{path: [column, ...]}for every readable CSV inpaths.- Parameters:
paths – one path, a sequence of them, or None.
- Returns:
a dict in the order given. A path that does not exist or cannot be parsed is absent from the result rather than mapped to an empty list – see rule 2. Use
missing()to ask which those were.
- spacr.columns.missing(paths) List[str][source]¶
Return the paths whose header could not be read by
headers().- Parameters:
paths – one CSV path, a sequence of paths, or None.
- spacr.columns.numeric_headers(paths, rows: int = 200) Dict[str, List[str]][source]¶
{path: [column, ...]}of the numeric columns that can be a response.- Parameters:
paths – one path, a sequence of them, or None.
rows – how many rows are read to tell a number from a label. The header decides the names and a short sample decides the type, so the cost stays the same for a score file of any size.
- Returns:
a dict in the order given. Identifier columns (
RESPONSE_EXCLUDED) are left out; an unreadable file is absent.
- spacr.columns.pred_missing(paths) List[str][source]¶
The readable files among
pathsthat have nopredcolumn.- Parameters:
paths – one path, a sequence of them, or None.
- spacr.columns.resolve(name, paths, *, what: str = 'column', setting: str = '') str[source]¶
nameif the CSVs have it, else raise with what they do have.- Parameters:
name – the column asked for.
paths – the CSVs to look in.
what – what kind of column, for the message (“response column”, “count column”).
setting – the settings key this came from, so the message names the control the user has to change.
- Raises:
ColumnNotFound – carrying
available, so a GUI can offer the list rather than re-reading the files to build it.
A case-insensitive match is accepted and returned in the file’s spelling:
Predictionsresolves topredictionswhen the file uses that name.