lunapi.parallel¶
Process-based project execution helpers for lunapi.
Attributes¶
Exceptions¶
Raised when table access is attempted on a file-output-only ProcResult. |
|
Raised when execution fails with |
Classes¶
Result returned by proc(), silent_proc(), proc_parallel(), and procn(). |
Functions¶
|
Resolve a list/set strata to the matching string given C-level (cmd, strata) pairs. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List available tables in a Luna |
|
Read a concatenated text-output table from a Luna |
Module Contents¶
- exception lunapi.parallel.FileOutputModeError[source]¶
Bases:
RuntimeErrorRaised when table access is attempted on a file-output-only ProcResult.
- class lunapi.parallel.ProcResult(_owner=None, errors=None, stdout=None, records=None, workers=1, _out_paths=None, _data=None, tables=None)[source]¶
Result returned by proc(), silent_proc(), proc_parallel(), and procn().
In memory mode (default): table data lives in the C-level cache of _owner; all table queries delegate there.
In file-output mode (out_db / out_text): _owner is None and table data was written directly to disk. Metadata (errors, records, out_paths) is still available; table queries raise FileOutputModeError.
- copy()[source]¶
Return a frozen copy of the current results.
The returned
ProcResultowns its data independently of the project cache, so subsequentproc()calls do not affect it. Useful when callingproc()in a loop:res = {} for stage in ['N1', 'N2', 'N3', 'R']: proj.var('stage', stage) res[stage] = proj.silent_proc(cmdstr).copy() res['N1']['STATS: CH_STAGE'] res['N1'].table('STATS', 'CH_STAGE')
- exception lunapi.parallel.ProcError(message: str, result: ProcResult)[source]¶
Bases:
RuntimeErrorRaised when execution fails with
strict=True.
- lunapi.parallel.coerce_strata(pairs, cmd, strata)[source]¶
Resolve a list/set strata to the matching string given C-level (cmd, strata) pairs.
pairsis the list of(cmd, strata)tuples returned byeng.strata()/edf.strata(). If strata is already a string it is returned unchanged. A list or set is matched order-independently against the_-delimited factor tokens in each available strata string.
- lunapi.parallel.run_parallel_project(project, cmdstr: str, *, workers=None, batch_size=None, params=None, param_file=None, strict: bool = False, progress=None, out_db=None, out_text=None, in_memory=None, n1=None, n2=None, ids=None, skip=None) ParallelProcResult[source]¶
- lunapi.parallel.list_text_tables(path, id=None) pandas.DataFrame[source]¶
List available tables in a Luna
-ttext-output folder.Inspects one individual subdirectory and returns a summary of available command/strata combinations based on the filenames present.
- Parameters:
path (str or Path) – Root folder passed as
out_text.id (str, optional) – Individual ID (subdirectory name) to inspect. Defaults to the first subdirectory in sorted order.
- Returns:
Columns:
command,strata,file.stratais'BL'for the baseline (no factors) or the factor name(s) joined by'_'(e.g.'CH','B_CH').- Return type:
pd.DataFrame
- lunapi.parallel.read_text_table(path, cmd_or_file, factors=None) pandas.DataFrame[source]¶
Read a concatenated text-output table from a Luna
-tdirectory.Finds every per-individual file that matches the requested command/strata combination and concatenates them into a single DataFrame — equivalent to:
awk 'NR==1 || FNR!=1' path/*/COMMAND_FACTOR.txt
Factor ordering in the filename is handled automatically; both
.txtand.txt.gzfiles are supported.- Parameters:
path (str or Path) – Root folder passed as
out_text.cmd_or_file (str, tuple, or list) –
One of:
A bare command name:
'HEADERS'(baseline strata)A filename:
'HEADERS_CH.txt'or'HEADERS_CH.txt.gz'A sequence:
('HEADERS', 'CH')or['HEADERS', ['B','CH']]
factors (str or list of str, optional) – Factor(s) when cmd_or_file is a plain command name, e.g.
factors='CH'orfactors=['B', 'CH'].
- Return type:
pd.DataFrame