Skip to content

Commit

Permalink
Add model.name getter and setter
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 113af0ecf5fc864b228e368e6fa297af640464cb
  • Loading branch information
drew committed Nov 15, 2021
1 parent c1eae89 commit a2a431c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/gretel_client/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,23 @@ def data_source(self, data_source: str):
)
self.model_config["models"][0][self.model_type]["data_source"] = data_source

@property
def name(self) -> Optional[str]:
"""Get the name of the model. If no name is specified, a
random name will be selected when the model is submitted
to the backend.
"""
return self.model_config.get("name")

@name.setter
def name(self, new_name: str):
"""Update the name of the model
Args:
new_name: The new name of the model
"""
self.model_config["name"] = new_name

def delete(self) -> Optional[dict]:
"""Deletes the remote model."""
if self.model_id:
Expand Down
9 changes: 9 additions & 0 deletions tests/gretel_client/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,12 @@ def test_synth_report_output(m: Model, get_fixture: Callable):
]
for field in expected_fields:
assert field in peek.keys()


def test_can_name_model(m: Model):
assert m.name == "my-awesome-model"
new_name = "my-model"
m.name = new_name
assert m.name == new_name
assert m.model_config["name"] == new_name
assert m._local_model_config["name"] == new_name

0 comments on commit a2a431c

Please sign in to comment.