Parse the XML debug tables file and extract required tables as pandas DataFrames.
(tables_path: Path)
| 34 | |
| 35 | |
| 36 | def parse_tables(tables_path: Path) -> Tables: |
| 37 | """ |
| 38 | Parse the XML debug tables file and extract required tables as pandas DataFrames. |
| 39 | """ |
| 40 | required_tables = {"queue", "group", "perf", "source"} |
| 41 | try: |
| 42 | tree = ET.parse(tables_path) # nosec B314 |
| 43 | except ET.ParseError as e: |
| 44 | raise ValueError(f"Failed to parse XML tables file {tables_path}: {e}") |
| 45 | |
| 46 | tables: Dict[str, pd.DataFrame] = {} |
| 47 | for table in tree.getroot().findall("table"): |
| 48 | name = table.attrib.get("name") |
| 49 | if name in required_tables: |
| 50 | text = table.text or "" |
| 51 | tables[name] = pd.read_csv(io.StringIO(text)) |
| 52 | |
| 53 | missing = required_tables - tables.keys() |
| 54 | if missing: |
| 55 | raise ValueError(f"Missing required tables in XML: {missing}") |
| 56 | |
| 57 | return Tables(**tables) |
| 58 | |
| 59 | |
| 60 | def get_trace_file_objects(trace_file_path: Path) -> list[Dict[str, Any]]: |
no test coverage detected