1414REQUIRES_SINGLE_FILE = frozenset (["csv" , "joblib" , "file" ])
1515
1616
17+ def _assert_is_pandas_df (x ):
18+ import pandas as pd
19+
20+ if not isinstance (x , pd .DataFrame ):
21+ raise NotImplementedError (
22+ "Currently only pandas.DataFrame can be saved to a CSV."
23+ )
24+
25+
1726def load_data (
1827 meta : Meta ,
1928 fs ,
@@ -67,6 +76,16 @@ def load_data(
6776
6877 return pd .read_csv (fs .open (path_to_file ))
6978
79+ elif meta .type == "feather" :
80+ import pandas as pd
81+
82+ return pd .read_feather (fs .open (path_to_file ))
83+
84+ elif meta .type == "parquet" :
85+ import pandas as pd
86+
87+ return pd .read_parquet (fs .open (path_to_file ))
88+
7089 elif meta .type == "table" :
7190 import pandas as pd
7291
@@ -93,28 +112,35 @@ def save_data(
93112 # TODO: would be useful to have singledispatch func for a "default saver"
94113 # as argument to board, and then type dispatchers for explicit cases
95114 # of saving / loading objects different ways.
115+
116+ if apply_suffix :
117+ final_name = f"{ fname } .{ type } "
118+ else :
119+ final_name = fname
120+
96121 if type == "csv" :
97- import pandas as pd
122+ _assert_is_pandas_df ( obj )
98123
99- if apply_suffix :
100- fname = f"{ fname } .{ type } "
124+ obj .to_csv (final_name , index = False )
125+
126+ elif type == "feather" :
127+ _assert_is_pandas_df (obj )
128+
129+ obj .to_feather (final_name )
130+
131+ elif type == "parquet" :
132+ _assert_is_pandas_df (obj )
133+
134+ obj .to_parquet (final_name )
101135
102- if not isinstance (obj , pd .DataFrame ):
103- raise NotImplementedError (
104- "Currently only pandas.DataFrame can be saved to a CSV."
105- )
106- obj .to_csv (fname , index = False )
107136 elif type == "joblib" :
108137 import joblib
109138
110- if apply_suffix :
111- fname = f"{ fname } .{ type } "
112-
113- joblib .dump (obj , fname )
139+ joblib .dump (obj , final_name )
114140 else :
115141 raise NotImplementedError (f"Cannot save type: { type } " )
116142
117- return fname
143+ return final_name
118144
119145
120146def default_title (obj , name ):
0 commit comments