(content: bytes)
| 39 | |
| 40 | |
| 41 | def _read_csv(content: bytes) -> pd.DataFrame: |
| 42 | try: |
| 43 | import chardet |
| 44 | except Exception: |
| 45 | chardet = None |
| 46 | encoding = "utf-8" |
| 47 | if chardet: |
| 48 | detected = chardet.detect(content) |
| 49 | encoding = detected.get("encoding") or encoding |
| 50 | try: |
| 51 | return pd.read_csv(BytesIO(content), encoding=encoding) |
| 52 | except Exception as exc: |
| 53 | raise ValidationError(f"Failed to read CSV: {exc}", field="file") |
| 54 | |
| 55 | |
| 56 | def _read_excel(content: bytes) -> pd.DataFrame: |
no test coverage detected