11
11
12
12
from . import api , exceptions , utils , validators
13
13
from .projects import Project
14
- from .schemas import DatasetSchema , ModelSchema , ShellModelSchema
14
+ from .schemas import BaselineModelSchema , DatasetSchema , ModelSchema , ShellModelSchema
15
15
from .tasks import TaskType
16
16
from .version import __version__ # noqa: F401
17
17
@@ -216,7 +216,6 @@ def create_or_load_project(
216
216
def add_model (
217
217
self ,
218
218
model_config_file_path : str ,
219
- task_type : TaskType ,
220
219
model_package_dir : Optional [str ] = None ,
221
220
sample_data : Optional [pd .DataFrame ] = None ,
222
221
force : bool = False ,
@@ -452,7 +451,7 @@ def add_baseline_model(
452
451
"""
453
452
**Coming soon...**
454
453
455
- Add a baseline model to the project.
454
+ Adds a baseline model to the project.
456
455
457
456
Baseline models should be added together with training and validation
458
457
sets. A model will then be trained on the platform using AutoML, using
@@ -508,7 +507,7 @@ def add_baseline_model(
508
507
model_config = {}
509
508
if model_config_file_path is not None :
510
509
model_config = utils .read_yaml (model_config_file_path )
511
- model_data = schemas . BaselineModelSchema ().load (model_config )
510
+ model_data = BaselineModelSchema ().load (model_config )
512
511
513
512
# Copy relevant resources to temp directory
514
513
with tempfile .TemporaryDirectory () as temp_dir :
@@ -525,7 +524,6 @@ def add_dataset(
525
524
self ,
526
525
file_path : str ,
527
526
dataset_config_file_path : str ,
528
- task_type : TaskType ,
529
527
project_id : str = None ,
530
528
force : bool = False ,
531
529
):
@@ -584,8 +582,9 @@ class probabilities. For example, for a binary classification
584
582
Delimiter to use. E.g. `'\\t'`.
585
583
force : bool
586
584
If :obj:`add_dataset` is called when there is already a dataset of the same type
587
- in the staging area, when ``force=True``, the existing staged dataset will be overwritten
588
- by the new one. When ``force=False``, the user will be prompted to confirm the overwrite.
585
+ in the staging area, when ``force=True``, the existing staged dataset will be
586
+ overwritten by the new one. When ``force=False``, the user will be prompted
587
+ to confirm the overwrite.
589
588
590
589
Notes
591
590
-----
@@ -734,17 +733,16 @@ class probabilities. For example, for a binary classification
734
733
735
734
def add_dataframe (
736
735
self ,
737
- df : pd .DataFrame ,
736
+ dataset_df : pd .DataFrame ,
738
737
dataset_config_file_path : str ,
739
- task_type : TaskType ,
740
738
project_id : str = None ,
741
739
force : bool = False ,
742
740
):
743
741
r"""Adds a dataset to a project's staging area (from a pandas DataFrame).
744
742
745
743
Parameters
746
744
----------
747
- df : pd.DataFrame
745
+ dataset_df : pd.DataFrame
748
746
Dataframe containing your dataset.
749
747
dataset_config_file_path : str
750
748
Path to the dataset configuration YAML file.
@@ -794,9 +792,10 @@ class probabilities. For example, for a binary classification
794
792
- ``sep`` : str, default ','
795
793
Delimiter to use. E.g. `'\\t'`.
796
794
force : bool
797
- If :obj:`add_dataframe` is called when there is already a dataset of the same type in the
798
- staging area, when ``force=True``, the existing staged dataset will be overwritten
799
- by the new one. When ``force=False``, the user will be prompted to confirm the overwrite.
795
+ If :obj:`add_dataframe` is called when there is already a dataset of the same
796
+ type in the staging area, when ``force=True``, the existing staged dataset will
797
+ be overwritten by the new one. When ``force=False``, the user will be prompted
798
+ to confirm the overwrite.
800
799
801
800
Notes
802
801
-----
@@ -858,7 +857,7 @@ class probabilities. For example, for a binary classification
858
857
You can now add this dataset to your project with:
859
858
860
859
>>> project.add_dataframe(
861
- ... df =df,
860
+ ... dataset_df =df,
862
861
... dataset_config_file_path='/path/to/dataset_config.yaml',
863
862
... )
864
863
@@ -899,7 +898,7 @@ class probabilities. For example, for a binary classification
899
898
You can now add this dataset to your project with:
900
899
901
900
>>> project.add_dataframe(
902
- ... df =df,
901
+ ... dataset_df =df,
903
902
... dataset_config_file_path='/path/to/dataset_config.yaml',
904
903
... )
905
904
@@ -913,16 +912,16 @@ class probabilities. For example, for a binary classification
913
912
>>> project.push()
914
913
"""
915
914
# --------------------------- Resource validations --------------------------- #
916
- if not isinstance (df , pd .DataFrame ):
915
+ if not isinstance (dataset_df , pd .DataFrame ):
917
916
raise exceptions .OpenlayerValidationError (
918
- f"- `df` is a `{ type (df )} `, but it must be of type `pd.DataFrame`. \n "
917
+ f"- `dataset_df` is a `{ type (dataset_df )} `, but it must be of type"
918
+ " `pd.DataFrame`. \n "
919
919
) from None
920
920
with tempfile .TemporaryDirectory () as tmp_dir :
921
921
file_path = os .path .join (tmp_dir , str (uuid .uuid1 ()))
922
- df .to_csv (file_path , index = False )
922
+ dataset_df .to_csv (file_path , index = False )
923
923
return self .add_dataset (
924
924
file_path = file_path ,
925
- task_type = task_type ,
926
925
project_id = project_id ,
927
926
dataset_config_file_path = dataset_config_file_path ,
928
927
force = force ,
@@ -946,21 +945,21 @@ def commit(self, message: str, project_id: int, force: bool = False):
946
945
947
946
Examples
948
947
--------
949
- A commit message is associated with a project version. We have a new project version every time
950
- any of its resources (namely, model and/or dataset) are updated. The commit message is supposed
951
- to be a short description of the changes from one version to the next.
948
+ A commit message is associated with a project version. We have a new project version
949
+ every time any of its resources (namely, model and/or dataset) are updated. The commit
950
+ message is supposed to be a short description of the changes from one version to the next.
952
951
953
- Let's say you have a project with a model and a dataset staged. You can confirm these resources
954
- are indeed in the staging area using the :obj:`status` method:
952
+ Let's say you have a project with a model and a dataset staged. You can confirm these
953
+ resources are indeed in the staging area using the :obj:`status` method:
955
954
956
955
>>> project.status()
957
956
958
957
Now, you can add a commit message to the staged resources.
959
958
960
959
>>> project.commit("Initial commit.")
961
960
962
- After adding the commit message, the resources are ready to be pushed to the platform. You use
963
- the :obj:`push` method to do so:
961
+ After adding the commit message, the resources are ready to be pushed to the platform.
962
+ You use the :obj:`push` method to do so:
964
963
965
964
>>> project.push()
966
965
"""
@@ -988,7 +987,9 @@ def commit(self, message: str, project_id: int, force: bool = False):
988
987
overwrite = "n"
989
988
990
989
if not force :
991
- with open (f"{ project_dir } /commit.yaml" , "r" ) as commit_file :
990
+ with open (
991
+ f"{ project_dir } /commit.yaml" , "r" , encoding = "UTF-8"
992
+ ) as commit_file :
992
993
commit = yaml .safe_load (commit_file )
993
994
print (
994
995
f"\t - Commit message: `{ commit ['message' ]} ` \n \t - Date: { commit ['date' ]} "
@@ -1005,7 +1006,7 @@ def commit(self, message: str, project_id: int, force: bool = False):
1005
1006
return
1006
1007
1007
1008
commit = dict (message = message , date = time .ctime ())
1008
- with open (f"{ project_dir } /commit.yaml" , "w" ) as commit_file :
1009
+ with open (f"{ project_dir } /commit.yaml" , "w" , encoding = "UTF-8" ) as commit_file :
1009
1010
yaml .dump (commit , commit_file )
1010
1011
1011
1012
print ("Committed!" )
@@ -1048,7 +1049,7 @@ def push(self, project_id: int):
1048
1049
)
1049
1050
return
1050
1051
1051
- with open (f"{ project_dir } /commit.yaml" , "r" ) as commit_file :
1052
+ with open (f"{ project_dir } /commit.yaml" , "r" , encoding = "UTF-8" ) as commit_file :
1052
1053
commit = yaml .safe_load (commit_file )
1053
1054
1054
1055
# Validate bundle resources
@@ -1130,7 +1131,7 @@ def status(self, project_id: int):
1130
1131
print ("Use the `commit` method to add a commit message to your changes." )
1131
1132
return
1132
1133
1133
- with open (f"{ project_dir } /commit.yaml" , "r" ) as commit_file :
1134
+ with open (f"{ project_dir } /commit.yaml" , "r" , encoding = "UTF-8" ) as commit_file :
1134
1135
commit = yaml .safe_load (commit_file )
1135
1136
print ("The following resources are committed, waiting to be pushed:" )
1136
1137
for file in os .listdir (project_dir ):
@@ -1209,8 +1210,8 @@ def _stage_resource(
1209
1210
"""
1210
1211
if resource_name not in VALID_RESOURCE_NAMES :
1211
1212
raise ValueError (
1212
- f "Resource name must be one of 'baseline-model', 'model', 'training', or 'validation', "
1213
- f" but got '{ resource_name } '."
1213
+ "Resource name must be one of 'baseline-model', 'model', 'training', or"
1214
+ f" 'validation', but got '{ resource_name } '."
1214
1215
)
1215
1216
1216
1217
project_dir = f"{ OPENLAYER_DIR } /{ project_id } /staging"
@@ -1220,15 +1221,17 @@ def _stage_resource(
1220
1221
if resource_name == "model" and "baseline-model" in resources_staged :
1221
1222
raise exceptions .OpenlayerException (
1222
1223
"Trying to stage a `model` when there is a `baseline-model` already staged."
1223
- + " You can either add a `model` or a `baseline-model`, but not both at the same time."
1224
- + " Please remove one of them from the staging area using the `restore` method."
1224
+ + " You can either add a `model` or a `baseline-model`, but not both at the"
1225
+ + " same time. Please remove one of them from the staging area using the"
1226
+ + " `restore` method."
1225
1227
) from None
1226
1228
1227
1229
if resource_name == "baseline-model" and "model" in resources_staged :
1228
1230
raise exceptions .OpenlayerException (
1229
1231
"Trying to stage a `baseline-model` when there is a `model` already staged."
1230
- + " You can either add a `model` or a `baseline-model`, but not both at the same time."
1231
- + " Please remove one of them from the staging area using the `restore` method."
1232
+ + " You can either add a `model` or a `baseline-model`, but not both at the"
1233
+ + " same time. Please remove one of them from the staging area using the"
1234
+ + " `restore` method."
1232
1235
) from None
1233
1236
1234
1237
if resource_name in resources_staged :
0 commit comments