Stacked input
Load one logical table from one or more CSV files.
Any config key that names a data file may name several; the files are stacked into a single table under a strict contract: every file must exist, all files must share one column set (unless a caller opts into zero-filled column union), and the key column must be unique within and across files. Violations raise StackedInputError, so a multi-source load either works exactly like the equivalent single file or fails loudly.
as_path_list(spec, label)
Normalize a config value that may be a single path or a list of paths.
Source code in may/utils/stacked_input.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
load_stacked_csv(paths, *, label, key_column=None, column_policy='strict', **read_csv_kwargs)
Read one or more CSVs and concatenate them into a single DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
List of file paths (already resolved). All must exist. |
required | |
label
|
Human-readable name of the input, used in error messages. |
required | |
key_column
|
Column that must be unique across the stacked table. A string names the column; 0 means "first column of the first file". None skips the uniqueness check (rows have no natural key). |
None
|
|
column_policy
|
"strict" means all files must have the same column set. "union_zero_fill" means columns are unioned and a column absent from a file is zero-filled for that file's rows, with a warning. |
'strict'
|
|
**read_csv_kwargs
|
Passed through to pandas.read_csv. low_memory defaults to False, giving each file one dtype per column. |
{}
|
Returns:
| Type | Description |
|---|---|
|
The concatenated DataFrame, columns in first-file order (strict) or |
|
|
first-seen order (union), index reset. |
Source code in may/utils/stacked_input.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |