1111
1212from . import api , exceptions , utils , validators
1313from .projects import Project
14- from .schemas import DatasetSchema , ModelSchema , ShellModelSchema
14+ from .schemas import BaselineModelSchema , DatasetSchema , ModelSchema , ShellModelSchema
1515from .tasks import TaskType
1616from .version import __version__ # noqa: F401
1717
@@ -216,7 +216,6 @@ def create_or_load_project(
216216 def add_model (
217217 self ,
218218 model_config_file_path : str ,
219- task_type : TaskType ,
220219 model_package_dir : Optional [str ] = None ,
221220 sample_data : Optional [pd .DataFrame ] = None ,
222221 force : bool = False ,
@@ -452,7 +451,7 @@ def add_baseline_model(
452451 """
453452 **Coming soon...**
454453
455- Add a baseline model to the project.
454+ Adds a baseline model to the project.
456455
457456 Baseline models should be added together with training and validation
458457 sets. A model will then be trained on the platform using AutoML, using
@@ -508,7 +507,7 @@ def add_baseline_model(
508507 model_config = {}
509508 if model_config_file_path is not None :
510509 model_config = utils .read_yaml (model_config_file_path )
511- model_data = schemas . BaselineModelSchema ().load (model_config )
510+ model_data = BaselineModelSchema ().load (model_config )
512511
513512 # Copy relevant resources to temp directory
514513 with tempfile .TemporaryDirectory () as temp_dir :
@@ -525,7 +524,6 @@ def add_dataset(
525524 self ,
526525 file_path : str ,
527526 dataset_config_file_path : str ,
528- task_type : TaskType ,
529527 project_id : str = None ,
530528 force : bool = False ,
531529 ):
@@ -584,8 +582,9 @@ class probabilities. For example, for a binary classification
584582 Delimiter to use. E.g. `'\\t'`.
585583 force : bool
586584 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.
589588
590589 Notes
591590 -----
@@ -734,17 +733,16 @@ class probabilities. For example, for a binary classification
734733
735734 def add_dataframe (
736735 self ,
737- df : pd .DataFrame ,
736+ dataset_df : pd .DataFrame ,
738737 dataset_config_file_path : str ,
739- task_type : TaskType ,
740738 project_id : str = None ,
741739 force : bool = False ,
742740 ):
743741 r"""Adds a dataset to a project's staging area (from a pandas DataFrame).
744742
745743 Parameters
746744 ----------
747- df : pd.DataFrame
745+ dataset_df : pd.DataFrame
748746 Dataframe containing your dataset.
749747 dataset_config_file_path : str
750748 Path to the dataset configuration YAML file.
@@ -794,9 +792,10 @@ class probabilities. For example, for a binary classification
794792 - ``sep`` : str, default ','
795793 Delimiter to use. E.g. `'\\t'`.
796794 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.
800799
801800 Notes
802801 -----
@@ -858,7 +857,7 @@ class probabilities. For example, for a binary classification
858857 You can now add this dataset to your project with:
859858
860859 >>> project.add_dataframe(
861- ... df =df,
860+ ... dataset_df =df,
862861 ... dataset_config_file_path='/path/to/dataset_config.yaml',
863862 ... )
864863
@@ -899,7 +898,7 @@ class probabilities. For example, for a binary classification
899898 You can now add this dataset to your project with:
900899
901900 >>> project.add_dataframe(
902- ... df =df,
901+ ... dataset_df =df,
903902 ... dataset_config_file_path='/path/to/dataset_config.yaml',
904903 ... )
905904
@@ -913,16 +912,16 @@ class probabilities. For example, for a binary classification
913912 >>> project.push()
914913 """
915914 # --------------------------- Resource validations --------------------------- #
916- if not isinstance (df , pd .DataFrame ):
915+ if not isinstance (dataset_df , pd .DataFrame ):
917916 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 "
919919 ) from None
920920 with tempfile .TemporaryDirectory () as tmp_dir :
921921 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 )
923923 return self .add_dataset (
924924 file_path = file_path ,
925- task_type = task_type ,
926925 project_id = project_id ,
927926 dataset_config_file_path = dataset_config_file_path ,
928927 force = force ,
@@ -946,21 +945,21 @@ def commit(self, message: str, project_id: int, force: bool = False):
946945
947946 Examples
948947 --------
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.
952951
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:
955954
956955 >>> project.status()
957956
958957 Now, you can add a commit message to the staged resources.
959958
960959 >>> project.commit("Initial commit.")
961960
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:
964963
965964 >>> project.push()
966965 """
@@ -988,7 +987,9 @@ def commit(self, message: str, project_id: int, force: bool = False):
988987 overwrite = "n"
989988
990989 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 :
992993 commit = yaml .safe_load (commit_file )
993994 print (
994995 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):
10051006 return
10061007
10071008 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 :
10091010 yaml .dump (commit , commit_file )
10101011
10111012 print ("Committed!" )
@@ -1048,7 +1049,7 @@ def push(self, project_id: int):
10481049 )
10491050 return
10501051
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 :
10521053 commit = yaml .safe_load (commit_file )
10531054
10541055 # Validate bundle resources
@@ -1130,7 +1131,7 @@ def status(self, project_id: int):
11301131 print ("Use the `commit` method to add a commit message to your changes." )
11311132 return
11321133
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 :
11341135 commit = yaml .safe_load (commit_file )
11351136 print ("The following resources are committed, waiting to be pushed:" )
11361137 for file in os .listdir (project_dir ):
@@ -1209,8 +1210,8 @@ def _stage_resource(
12091210 """
12101211 if resource_name not in VALID_RESOURCE_NAMES :
12111212 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 } '."
12141215 )
12151216
12161217 project_dir = f"{ OPENLAYER_DIR } /{ project_id } /staging"
@@ -1220,15 +1221,17 @@ def _stage_resource(
12201221 if resource_name == "model" and "baseline-model" in resources_staged :
12211222 raise exceptions .OpenlayerException (
12221223 "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."
12251227 ) from None
12261228
12271229 if resource_name == "baseline-model" and "model" in resources_staged :
12281230 raise exceptions .OpenlayerException (
12291231 "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."
12321235 ) from None
12331236
12341237 if resource_name in resources_staged :
0 commit comments