MCPcopy Index your code
hub / github.com/microsoft/qlib / read_as_df

Function read_as_df

scripts/dump_bin.py:20–50  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

18
19
20def 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
53class DumpDataBase:

Callers 2

_get_source_dataMethod · 0.85
_read_dfMethod · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected