Skip to content

Commit 89a9ded

Browse files
gustavocidornelaswhoseoyster
authored andcommitted
Squash pylint errors
1 parent 5ca2a4e commit 89a9ded

File tree

5 files changed

+116
-83
lines changed

5 files changed

+116
-83
lines changed

openlayer/__init__.py

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from . import api, exceptions, utils, validators
1313
from .projects import Project
14-
from .schemas import DatasetSchema, ModelSchema, ShellModelSchema
14+
from .schemas import BaselineModelSchema, DatasetSchema, ModelSchema, ShellModelSchema
1515
from .tasks import TaskType
1616
from .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:

openlayer/exceptions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""A collection of the different Openlayer Python client exceptions and their error codes.
2+
3+
Typical usage example:
4+
5+
if project is None:
6+
raise errors.OpenlayerResourceNotFound(f"Project {project_id} does not exist")
7+
"""
18
from typing import Dict
29

310

@@ -21,11 +28,15 @@ def __init__(self, message, errcode=None):
2128

2229

2330
class OpenlayerValidationError(OpenlayerException):
31+
"""Failed resource validations"""
32+
2433
def __init__(self, message):
2534
super().__init__(message)
2635

2736

2837
class OpenlayerSubscriptionPlanException(OpenlayerException):
38+
"""Subscription plan exception class"""
39+
2940
def __init__(self, message, context=None, mitigation=None):
3041
context = context or "You have reached your subscription plan's limits. \n"
3142
mitigation = mitigation or "To upgrade your plan, visit https://openlayer.com"

openlayer/projects.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Module for the Project class.
3+
"""
4+
15
from . import tasks
26

37

@@ -39,15 +43,15 @@ def add_model(
3943
*args,
4044
**kwargs,
4145
):
42-
return self.client.add_model(
43-
*args, project_id=self.id, task_type=tasks.TaskType(self.taskType), **kwargs
44-
)
46+
"""Adds a model to a project's staging area."""
47+
return self.client.add_model(*args, project_id=self.id, **kwargs)
4548

4649
def add_baseline_model(
4750
self,
4851
*args,
4952
**kwargs,
5053
):
54+
"""Adds a baseline model to the project."""
5155
return self.client.add_baseline(
5256
*args, project_id=self.id, task_type=tasks.TaskType(self.taskType), **kwargs
5357
)
@@ -57,23 +61,25 @@ def add_dataset(
5761
*args,
5862
**kwargs,
5963
):
60-
return self.client.add_dataset(
61-
*args, project_id=self.id, task_type=tasks.TaskType(self.taskType), **kwargs
62-
)
64+
"""Adds a dataset to a project's staging area (from a csv)."""
65+
return self.client.add_dataset(*args, project_id=self.id, **kwargs)
6366

6467
def add_dataframe(self, *args, **kwargs):
65-
return self.client.add_dataframe(
66-
*args, project_id=self.id, task_type=tasks.TaskType(self.taskType), **kwargs
67-
)
68+
"""Adds a dataset to a project's staging area (from a pandas DataFrame)."""
69+
return self.client.add_dataframe(*args, project_id=self.id, **kwargs)
6870

6971
def commit(self, *args, **kwargs):
72+
"""Adds a commit message to staged resources."""
7073
return self.client.commit(*args, project_id=self.id, **kwargs)
7174

7275
def push(self, *args, **kwargs):
76+
"""Pushes the commited resources to the platform."""
7377
return self.client.push(*args, project_id=self.id, **kwargs)
7478

7579
def status(self, *args, **kwargs):
80+
"""Shows the state of the staging area."""
7681
return self.client.status(*args, project_id=self.id, **kwargs)
7782

7883
def restore(self, *args, **kwargs):
84+
"""Removes the resource specified by ``resource_name`` from the staging area."""
7985
return self.client.restore(*args, project_id=self.id, **kwargs)

openlayer/utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""Series of helper functions and classes that are used throughout the
2+
OpenLayer Python client.
3+
"""
14
import os
25
import sys
36
import traceback
@@ -38,7 +41,7 @@ def write_python_version(directory: str):
3841
Args:
3942
directory (str): the directory to write the file to.
4043
"""
41-
with open(f"{directory}/python_version", "w") as file:
44+
with open(f"{directory}/python_version", "w", encoding="UTF-8") as file:
4245
file.write(
4346
str(sys.version_info.major)
4447
+ "."
@@ -67,7 +70,7 @@ def read_yaml(filename: str) -> dict:
6770
Returns:
6871
dict: the dictionary representation of the YAML file.
6972
"""
70-
with open(filename, "r") as stream:
73+
with open(filename, "r", encoding="UTF-8") as stream:
7174
return yaml.safe_load(stream)
7275

7376

@@ -78,7 +81,7 @@ def write_yaml(dictionary: dict, filename: str):
7881
dictionary (dict): the dictionary to write to a YAML file.
7982
dir (str): the directory to write the file to.
8083
"""
81-
with open(filename, "w") as stream:
84+
with open(filename, "w", encoding="UTF-8") as stream:
8285
yaml.dump(dictionary, stream)
8386

8487

@@ -108,4 +111,4 @@ def list_resources_in_bundle(bundle_path: str) -> list:
108111
for resource in os.listdir(bundle_path):
109112
if resource in VALID_RESOURCES:
110113
resources.append(resource)
111-
return resources
114+
return resources

0 commit comments

Comments
 (0)