MCPcopy Index your code
hub / github.com/OpenBMB/ChatDev / parse_batch_file

Function parse_batch_file

server/services/batch_parser.py:23–38  ·  view source on GitHub ↗

Parse a CSV/Excel batch file and return tasks plus file base name.

(content: bytes, filename: str)

Source from the content-addressed store, hash-verified

21
22
23def parse_batch_file(content: bytes, filename: str) -> Tuple[List[BatchTask], str]:
24 """Parse a CSV/Excel batch file and return tasks plus file base name."""
25 suffix = Path(filename or "").suffix.lower()
26 if suffix not in {".csv", ".xlsx", ".xls"}:
27 raise ValidationError("Unsupported file type; must be .csv or .xlsx/.xls", field="file")
28
29 if suffix == ".csv":
30 df = _read_csv(content)
31 else:
32 df = _read_excel(content)
33
34 file_base = Path(filename).stem or "batch"
35 tasks = _parse_dataframe(df)
36 if not tasks:
37 raise ValidationError("Batch file contains no tasks", field="file")
38 return tasks, file_base
39
40
41def _read_csv(content: bytes) -> pd.DataFrame:

Callers 1

execute_batchFunction · 0.90

Calls 4

ValidationErrorClass · 0.90
_read_csvFunction · 0.85
_read_excelFunction · 0.85
_parse_dataframeFunction · 0.85

Tested by

no test coverage detected