ump_intake.parsing
module ump-intake
Parsing (stage 1): CSV or XLSX bytes, an inline series, or connector rows to a ParsedTable.
Title rows, blank rows and printed total or subtotal rows are separated from the data; hidden rows and merged
cells in a workbook are reported as known issues. Moved here unchanged from apps/onboarding so the
onboarding wizard and the data catalogue (apps/data) parse deliveries the same way.
Classes
Section titled “Classes”ParsedTable
Section titled “ParsedTable”class
class ParsedTableFields
| Name | Type | Default | Description |
|---|---|---|---|
kind | str | ||
filename | str | ||
raw_bytes | bytes | ||
columns | list[str] | ||
rows | list[list[Any]] | ||
printed_totals | dict[str, float] | field(default_factory=dict) | |
issues | list[str] | field(default_factory=list) | |
skipped_rows | int | 0 |
Methods and properties (2)
sha256 property
sha256: strinit constructor
ParsedTable( self, kind: str, filename: str, raw_bytes: bytes, columns: list[str], rows: list[list[Any]], printed_totals: dict[str, float] = dict(), issues: list[str] = list(), skipped_rows: int = 0,) -> NoneSource: packages/ump-intake/src/ump_intake/parsing.py, line 25
Functions
Section titled “Functions”to_csv
Section titled “to_csv”function
def to_csv( columns: list[str], rows: list[list[Any]], printed: dict[str, float] | None = None,) -> strCSV text with \n line ends; an optional printed Total row at the bottom.
Source: packages/ump-intake/src/ump_intake/parsing.py, line 41
to_number
Section titled “to_number”function
def to_number(v: Any) -> float | NoneSource: packages/ump-intake/src/ump_intake/parsing.py, line 53
to_date
Section titled “to_date”function
def to_date(v: Any) -> date | NoneSource: packages/ump-intake/src/ump_intake/parsing.py, line 72
split_rows
Section titled “split_rows”function
def split_rows( header: list[str], body: list[list[Any]], issues: list[str],) -> tuple[list[list[Any]], dict[str, float], int]Separate data rows from blank and printed total rows.
Source: packages/ump-intake/src/ump_intake/parsing.py, line 88
header_index
Section titled “header_index”function
def header_index(rows: list[list[Any]]) -> intFirst row with at least two non-empty, non-numeric cells.
Source: packages/ump-intake/src/ump_intake/parsing.py, line 113
parse_csv_bytes
Section titled “parse_csv_bytes”function
def parse_csv_bytes(raw: bytes, filename: str) -> ParsedTableSource: packages/ump-intake/src/ump_intake/parsing.py, line 122
parse_xlsx_bytes
Section titled “parse_xlsx_bytes”function
def parse_xlsx_bytes(raw: bytes, filename: str, sheet: str | None = None) -> ParsedTableSource: packages/ump-intake/src/ump_intake/parsing.py, line 134
parse_inline
Section titled “parse_inline”function
def parse_inline(series: dict[str, Any]) -> ParsedTable{dates, kpi, spend: {ch: [...]}, controls: {...}, kpi_name?} (the adapter SeriesData shape).
Source: packages/ump-intake/src/ump_intake/parsing.py, line 162
parse_rows
Section titled “parse_rows”function
def parse_rows( columns: Sequence[str], rows: Sequence[Sequence[Any] | Mapping[str, Any]], name: str = 'connected',) -> ParsedTableRows read through a data connection (a list of lists, or of dicts read in columns order) to a
table, so mapping suggestions and build_panel work on connected data exactly as on a file. Blank and
printed total rows are separated the same way. raw_bytes is the CSV rendering, held in memory only:
callers decide whether the copy policy lets it be stored.
Source: packages/ump-intake/src/ump_intake/parsing.py, line 178
parse_upload
Section titled “parse_upload”function
def parse_upload(body: dict[str, Any]) -> ParsedTableSource: packages/ump-intake/src/ump_intake/parsing.py, line 192
Constants
Section titled “Constants”| Name | Type | Value | Description |
|---|---|---|---|
TOTAL_RE | re.compile('^\\s*(grand\\s+)?(sub)?total\\b', re.IGNORECASE) |