-
Notifications
You must be signed in to change notification settings - Fork 12
/
df_utils.py
53 lines (40 loc) · 1.07 KB
/
df_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
The `df_utils` module provides a consistent interface for loading data frames and saving them to disk.
Supported types: csv, parquet, json, jsonl, arrow
Example usage:
```python
import os
from oxen import df_utils
# load a data frame
df = df_utils.load("path/to/data.csv")
# save a data frame
df_utils.save(df, "path/to/save.csv")
```
"""
from .oxen import df_utils
import os
from polars import DataFrame
def load(
path: os.PathLike,
):
"""
Reads a file into a data frame. The file format is inferred from the file extension.
Supported types: csv, parquet, json, jsonl, arrow
Args:
path: `os.PathLike`
The path to the file to read.
"""
return df_utils.load(path)
def save(
data_frame: DataFrame,
path: os.PathLike,
):
"""
Saves a data frame to a file. The file format is inferred from the file extension.
Args:
data_frame: `DataFrame`
The polars data frame to save.
path: `os.PathLike`
The path to save the data frame to.
"""
return df_utils.save(data_frame, path)