11from src .commands .project_store_protocol import Model
22from src .commands .command_utils import convert_to_type , convert_to_ml_type
3+ from src .cliresult import chain , add_warning
34
45import numpy as np
56
7+ @chain
68def create (model : Model , alias : str , type : str , * args , ** kwargs ) -> str :
79 """Creates a new project with the given alias and type.
810
@@ -15,13 +17,14 @@ def create(model: Model, alias: str, type: str, *args, **kwargs) -> str:
1517 str: Optional message to display to the user.
1618 """
1719 if args :
18- print ( f"Warning: extra arguments { args } will be ignored." )
20+ add_warning ( model , f"Warning: extra arguments { args } will be ignored." )
1921 elif kwargs :
20- print ( f"Warning: extra arguments { kwargs } will be ignored." )
22+ add_warning ( model , f"Warning: extra arguments { kwargs } will be ignored." )
2123
2224 new_type = convert_to_type (type )
2325 return model .create (alias , new_type )
2426
27+ @chain
2528def delete (model : Model , alias : str , from_dir : bool = False , * args , ** kwargs ) -> str :
2629 """
2730 Deletes the project with the given alias.
@@ -34,12 +37,13 @@ def delete(model: Model, alias: str, from_dir: bool = False, *args, **kwargs) ->
3437 str: Optional message to display to the user.
3538 """
3639 if args :
37- print ( f"Warning: extra arguments { args } will be ignored." )
40+ add_warning ( model , f"Warning: extra arguments { args } will be ignored." )
3841 elif kwargs :
39- print ( f"Warning: extra arguments { kwargs } will be ignored." )
42+ add_warning ( model , f"Warning: extra arguments { kwargs } will be ignored." )
4043
4144 return model .delete (alias , from_dir = from_dir )
4245
46+ @chain
4347def list_projects (model : Model , * args , ** kwargs ) -> str :
4448 """
4549 Lists all projects in the model.
@@ -51,12 +55,13 @@ def list_projects(model: Model, *args, **kwargs) -> str:
5155 list[str]: A list of project aliases.
5256 """
5357 if args :
54- print ( f"Warning: extra arguments { args } will be ignored." )
58+ add_warning ( model , f"Warning: extra arguments { args } will be ignored." )
5559 elif kwargs :
56- print ( f"Warning: extra arguments { kwargs } will be ignored." )
60+ add_warning ( model , f"Warning: extra arguments { kwargs } will be ignored." )
5761
5862 return model .list_projects ()
5963
64+ @chain
6065def set_current_project (model : Model , alias : str , * args , ** kwargs ) -> str :
6166 """
6267 Sets the current project to the one with the given alias.
@@ -69,9 +74,9 @@ def set_current_project(model: Model, alias: str, *args, **kwargs) -> str:
6974 str: Optional message to display to the user.
7075 """
7176 if args :
72- print ( f"Warning: extra arguments { args } will be ignored." )
77+ add_warning ( model , f"Warning: extra arguments { args } will be ignored." )
7378 elif kwargs :
74- print ( f"Warning: extra arguments { kwargs } will be ignored." )
79+ add_warning ( model , f"Warning: extra arguments { kwargs } will be ignored." )
7580
7681 return model .set_current_project (alias )
7782
@@ -87,24 +92,32 @@ def pcp(model: Model) -> str:
8792 """
8893 return model .pcp ()
8994
90- def add_data (model : Model , df_name : str , * args , ** kwargs ) -> str :
95+ @chain
96+ def add_data (model : Model , df_name : str , delimiter : str = ',' , * args , ** kwargs ) -> str :
9197 """
9298 Adds a DataFrame to the current project.
99+
100+ Supported file extensions:
101+ - .csv
102+ - .txt
103+ - .xls, .xlsx
104+ - .json
105+ - .xml
106+ - .html
93107
94108 Args:
95109 model (Model): Parsed automatically by the command parser.
96- df_name (str): Name of the DataFrame to add.
97-
98- Returns:
99- None
110+ alias (str): Name of the DataFrame to add.
111+ delimiter (str): Delimiter used in the DataFrame (ignored if format is not '.txt' or '.csv').
100112 """
101113 if args :
102- print ( f"Warning: extra arguments { args } will be ignored." )
114+ add_warning ( model , f"Warning: extra arguments { args } will be ignored." )
103115 elif kwargs :
104- print ( f"Warning: extra arguments { kwargs } will be ignored." )
116+ add_warning ( model , f"Warning: extra arguments { kwargs } will be ignored." )
105117
106- return model .add_data (df_name )
118+ return model .add_data (df_name , delimiter = delimiter )
107119
120+ @chain
108121def read_data (model : Model , head : int = 5 , * args , ** kwargs ) -> str :
109122 """
110123 Reads the data from the current project.
@@ -117,12 +130,31 @@ def read_data(model: Model, head: int = 5, *args, **kwargs) -> str:
117130 str: A string representation of the DataFrame.
118131 """
119132 if args :
120- print ( f"Warning: extra arguments { args } will be ignored." )
133+ add_warning ( model , f"Warning: extra arguments { args } will be ignored." )
121134 elif kwargs :
122- print ( f"Warning: extra arguments { kwargs } will be ignored." )
135+ add_warning ( model , f"Warning: extra arguments { kwargs } will be ignored." )
123136
124137 return model .read_data (head )
125138
139+ @chain
140+ def list_cols (model : Model , * args , ** kwargs ) -> str :
141+ """
142+ Lists the columns of dataframe in the current project.
143+
144+ Args:
145+ model (Model): Parsed automatically by the command parser.
146+
147+ Returns:
148+ str: A list of columns in the current project.
149+ """
150+ if args :
151+ add_warning (model , f"Warning: extra arguments { args } will be ignored." )
152+ elif kwargs :
153+ add_warning (model , f"Warning: extra arguments { kwargs } will be ignored." )
154+
155+ return model .list_cols ()
156+
157+ @chain
126158def make_X_y (model : Model , target : str , * args , ** kwargs ) -> str :
127159 """
128160 Creates the X and y arrays from the current project.
@@ -135,12 +167,13 @@ def make_X_y(model: Model, target: str, *args, **kwargs) -> str:
135167 str: Optional message to display to the user.
136168 """
137169 if args :
138- print ( f"Warning: extra arguments { args } will be ignored." )
170+ add_warning ( model , f"Warning: extra arguments { args } will be ignored." )
139171 elif kwargs :
140- print ( f"Warning: extra arguments { kwargs } will be ignored." )
172+ add_warning ( model , f"Warning: extra arguments { kwargs } will be ignored." )
141173
142174 return model .make_X_y (target )
143175
176+ @chain
144177def clean_data (model : Model , * args , ** kwargs ) -> str :
145178 """
146179 Cleans the data in the current project.
@@ -152,12 +185,13 @@ def clean_data(model: Model, *args, **kwargs) -> str:
152185 str: Optional message to display to the user.
153186 """
154187 if args :
155- print ( f"Warning: extra arguments { args } will be ignored." )
188+ add_warning ( model , f"Warning: extra arguments { args } will be ignored." )
156189 elif kwargs :
157- print ( f"Warning: extra arguments { kwargs } will be ignored." )
190+ add_warning ( model , f"Warning: extra arguments { kwargs } will be ignored." )
158191
159192 return model .clean_data ()
160193
194+ @chain
161195def log_model (model : Model , model_name : str , predictions : np .ndarray , params : dict [str , float | int | str ], * args , ** kwargs ) -> str :
162196 """
163197 Logs a model in the current project.
@@ -172,13 +206,14 @@ def log_model(model: Model, model_name: str, predictions: np.ndarray, params: di
172206 str: Optional message to display to the user.
173207 """
174208 if args :
175- print ( f"Warning: extra arguments { args } will be ignored." )
209+ add_warning ( model , f"Warning: extra arguments { args } will be ignored." )
176210 elif kwargs :
177- print ( f"Warning: extra arguments { kwargs } will be ignored." )
211+ add_warning ( model , f"Warning: extra arguments { kwargs } will be ignored." )
178212
179213 model_name = convert_to_ml_type (model_name )
180214 return model .log_model (model_name , predictions , params )
181215
216+ @chain
182217def summary (model : Model , * args , ** kwargs ) -> str :
183218 """
184219 Summarizes the current project.
@@ -190,12 +225,13 @@ def summary(model: Model, *args, **kwargs) -> str:
190225 str: A summary of the current project.
191226 """
192227 if args :
193- print ( f"Warning: extra arguments { args } will be ignored." )
228+ add_warning ( model , f"Warning: extra arguments { args } will be ignored." )
194229 elif kwargs :
195- print ( f"Warning: extra arguments { kwargs } will be ignored." )
230+ add_warning ( model , f"Warning: extra arguments { kwargs } will be ignored." )
196231
197232 return model .summary ()
198233
234+ @chain
199235def save (model : Model , overwrite : bool = False , * args , ** kwargs ) -> str :
200236 """
201237 Saves the current project.
@@ -208,12 +244,13 @@ def save(model: Model, overwrite: bool = False, *args, **kwargs) -> str:
208244 str: Optional message to display to the user.
209245 """
210246 if args :
211- print ( f"Warning: extra arguments { args } will be ignored." )
247+ add_warning ( model , f"Warning: extra arguments { args } will be ignored." )
212248 elif kwargs :
213- print ( f"Warning: extra arguments { kwargs } will be ignored." )
249+ add_warning ( model , f"Warning: extra arguments { kwargs } will be ignored." )
214250
215251 return model .save (overwrite = overwrite )
216252
253+ @chain
217254def load_project_from_file (model : Model , alias : str , * args , ** kwargs ) -> str :
218255 """
219256 Loads a project from a file.
@@ -226,12 +263,13 @@ def load_project_from_file(model: Model, alias: str, *args, **kwargs) -> str:
226263 str: Optional message to display to the user.
227264 """
228265 if args :
229- print ( f"Warning: extra arguments { args } will be ignored." )
266+ add_warning ( model , f"Warning: extra arguments { args } will be ignored." )
230267 elif kwargs :
231- print ( f"Warning: extra arguments { kwargs } will be ignored." )
268+ add_warning ( model , f"Warning: extra arguments { kwargs } will be ignored." )
232269
233270 return model .load_project_from_file (alias )
234271
272+ @chain
235273def plot (model : Model , cmd : str , labels : str | list [str ] | None = None , show : bool = False , * args , ** kwargs ) -> str :
236274 """
237275 Generates a plot based on the given command and labels.
@@ -248,12 +286,13 @@ def plot(model: Model, cmd: str, labels: str | list[str] | None = None, show: bo
248286 if labels is None :
249287 labels = []
250288 if args :
251- print ( f"Warning: extra arguments { args } will be ignored." )
289+ add_warning ( model , f"Warning: extra arguments { args } will be ignored." )
252290 elif kwargs :
253- print ( f"Warning: extra arguments { kwargs } will be ignored." )
291+ add_warning ( model , f"Warning: extra arguments { kwargs } will be ignored." )
254292
255293 return model .plot (cmd , labels , show )
256294
295+ @chain
257296def show (model : Model , * args , ** kwargs ) -> str :
258297 """
259298 Displays the plot for the current project.
@@ -265,12 +304,13 @@ def show(model: Model, *args, **kwargs) -> str:
265304 str: The result of the show command.
266305 """
267306 if args :
268- print ( f"Warning: extra arguments { args } will be ignored." )
307+ add_warning ( model , f"Warning: extra arguments { args } will be ignored." )
269308 elif kwargs :
270- print ( f"Warning: extra arguments { kwargs } will be ignored." )
309+ add_warning ( model , f"Warning: extra arguments { kwargs } will be ignored." )
271310
272311 return model .show ()
273312
313+ @chain
274314def stats (model : Model , * args , ** kwargs ) -> str :
275315 """
276316 Displays the statistics for the current project.
@@ -282,8 +322,8 @@ def stats(model: Model, *args, **kwargs) -> str:
282322 str: The result of the stats command.
283323 """
284324 if args :
285- print ( f"Warning: extra arguments { args } will be ignored." )
325+ add_warning ( model , f"Warning: extra arguments { args } will be ignored." )
286326 elif kwargs :
287- print ( f"Warning: extra arguments { kwargs } will be ignored." )
327+ add_warning ( model , f"Warning: extra arguments { kwargs } will be ignored." )
288328
289329 return model .stats ()
0 commit comments