Read a csv or parquet file into a pandas DataFrame. Parameters ---------- file_path : Union[str, Path] Path to the data file. **kwargs : Additional keyword arguments passed to the underlying pandas reader. Returns ------- pd.DataFrame
(file_path: Union[str, Path], **kwargs)
| 18 | |
| 19 | |
| 20 | def read_as_df(file_path: Union[str, Path], **kwargs) -> pd.DataFrame: |
| 21 | """ |
| 22 | Read a csv or parquet file into a pandas DataFrame. |
| 23 | |
| 24 | Parameters |
| 25 | ---------- |
| 26 | file_path : Union[str, Path] |
| 27 | Path to the data file. |
| 28 | **kwargs : |
| 29 | Additional keyword arguments passed to the underlying pandas |
| 30 | reader. |
| 31 | |
| 32 | Returns |
| 33 | ------- |
| 34 | pd.DataFrame |
| 35 | """ |
| 36 | file_path = Path(file_path).expanduser() |
| 37 | suffix = file_path.suffix.lower() |
| 38 | |
| 39 | keep_keys = {".csv": ("low_memory",)} |
| 40 | kept_kwargs = {} |
| 41 | for k in keep_keys.get(suffix, []): |
| 42 | if k in kwargs: |
| 43 | kept_kwargs[k] = kwargs[k] |
| 44 | |
| 45 | if suffix == ".csv": |
| 46 | return pd.read_csv(file_path, **kept_kwargs) |
| 47 | elif suffix == ".parquet": |
| 48 | return pd.read_parquet(file_path, **kept_kwargs) |
| 49 | else: |
| 50 | raise ValueError(f"Unsupported file format: {suffix}") |
| 51 | |
| 52 | |
| 53 | class DumpDataBase: |
no test coverage detected