Skip to content

Commit

Permalink
update artifact & dataframe domain init
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanSoley committed Aug 16, 2024
1 parent 7e65353 commit 6b9a25a
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 32 deletions.
72 changes: 58 additions & 14 deletions rubicon_ml/domain/artifact.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,65 @@
from __future__ import annotations
from dataclasses import dataclass
from typing import TYPE_CHECKING, List, Optional

from dataclasses import dataclass, field
from datetime import datetime
from typing import List, Optional
from rubicon_ml.domain.mixin import CommentMixin, InitMixin, TagMixin

from rubicon_ml.domain.mixin import CommentMixin, TagMixin
from rubicon_ml.domain.utils import uuid
if TYPE_CHECKING:
from datetime import datetime


@dataclass
class Artifact(TagMixin, CommentMixin):
name: str
@dataclass(init=False)
class Artifact(CommentMixin, InitMixin, TagMixin):
"""A domain-level artifact.
id: str = field(default_factory=uuid.uuid4)
description: Optional[str] = None
created_at: datetime = field(default_factory=datetime.utcnow)
tags: List[str] = field(default_factory=list)
comments: List[str] = field(default_factory=list)
name : str
The artifact's name.
comments : list of str, optional
Additional text information and observations about the artifact. Defaults to
`None`.
created_at : datetime, optional
The date and time the artifact was created. Defaults to `None` and uses
`datetime.datetime.now` to generate a UTC timestamp. `created_at` should be
left as `None` to allow for automatic generation.
description : str, optional
A description of the artifact. Defaults to `None`.
id : str, optional
The artifact's unique identifier. Defaults to `None` and uses `uuid.uuid4`
to generate a unique ID. `id` should be left as `None` to allow for automatic
generation.
parent_id : str, optional
The unique identifier of the project or experiment the artifact belongs to.
Defaults to `None`.
tags : list of str, optional
The values this artifact is tagged with. Defaults to `None`.
"""

name: str
comments: Optional[List[str]] = None
created_at: Optional["datetime"] = None
description: Optional[str] = None
id: Optional[str] = None
parent_id: Optional[str] = None
tags: Optional[List[str]] = None

def __init__(
self,
name: str,
comments: Optional[List[str]] = None,
created_at: Optional["datetime"] = None,
description: Optional[str] = None,
id: Optional[str] = None,
parent_id: Optional[str] = None,
tags: Optional[List[str]] = None,
**kwargs,
):
"""Initialize this domain artifact."""

self._check_extra_kwargs(kwargs)

self.name = name
self.comments = comments or []
self.created_at = self._init_created_at(created_at)
self.description = description
self.id = self._init_id(id)
self.parent_id = parent_id
self.tags = tags or []
73 changes: 59 additions & 14 deletions rubicon_ml/domain/dataframe.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,65 @@
from __future__ import annotations
from dataclasses import dataclass
from typing import TYPE_CHECKING, List, Optional

from dataclasses import dataclass, field
from datetime import datetime
from typing import List, Optional
from rubicon_ml.domain.mixin import CommentMixin, InitMixin, TagMixin

from rubicon_ml.domain.mixin import CommentMixin, TagMixin
from rubicon_ml.domain.utils import uuid
if TYPE_CHECKING:
from datetime import datetime


@dataclass
class Dataframe(TagMixin, CommentMixin):
id: str = field(default_factory=uuid.uuid4)
name: Optional[str] = None
description: Optional[str] = None
tags: List[str] = field(default_factory=list)
comments: List[str] = field(default_factory=list)
created_at: datetime = field(default_factory=datetime.utcnow)
@dataclass(init=False)
class Dataframe(CommentMixin, InitMixin, TagMixin):
"""A domain-level dataframe.
comments : list of str, optional
Additional text information and observations about the dataframe. Defaults to
`None`.
created_at : datetime, optional
The date and time the dataframe was created. Defaults to `None` and uses
`datetime.datetime.now` to generate a UTC timestamp. `created_at` should be
left as `None` to allow for automatic generation.
description : str, optional
A description of the dataframe. Defaults to `None`.
id : str, optional
The dataframe's unique identifier. Defaults to `None` and uses `uuid.uuid4`
to generate a unique ID. `id` should be left as `None` to allow for automatic
generation.
name : str, optional
The dataframe's name. Defaults to `None`.
parent_id : str, optional
The unique identifier of the project or experiment the dataframe belongs to.
Defaults to `None`.
tags : list of str, optional
The values this dataframe is tagged with. Defaults to `None`.
"""

comments: Optional[List[str]] = None
created_at: Optional["datetime"] = None
description: Optional[str] = None
id: Optional[str] = None
name: Optional[str] = None
parent_id: Optional[str] = None
tags: Optional[List[str]] = None

def __init__(
self,
comments: Optional[List[str]] = None,
created_at: Optional["datetime"] = None,
description: Optional[str] = None,
id: Optional[str] = None,
name: Optional[str] = None,
parent_id: Optional[str] = None,
tags: Optional[List[str]] = None,
**kwargs,
):
"""Initialize this doimain dataframe."""

self._check_extra_kwargs(kwargs)

self.comments = comments or []
self.created_at = self._init_created_at(created_at)
self.description = description
self.id = self._init_id(id)
self.name = name
self.parent_id = parent_id
self.tags = tags or []
2 changes: 1 addition & 1 deletion rubicon_ml/domain/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


@dataclass(init=False)
class Feature(TagMixin, InitMixin, CommentMixin):
class Feature(CommentMixin, InitMixin, TagMixin):
"""A domain-level feature.
name : str
Expand Down
2 changes: 1 addition & 1 deletion rubicon_ml/domain/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@dataclass(init=False)
class Metric(TagMixin, InitMixin, CommentMixin):
class Metric(CommentMixin, InitMixin, TagMixin):
"""A domain-level metric.
name : str
Expand Down
2 changes: 1 addition & 1 deletion rubicon_ml/domain/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


@dataclass(init=False)
class Parameter(TagMixin, InitMixin, CommentMixin):
class Parameter(CommentMixin, InitMixin, TagMixin):
"""A domain-level parameter.
name : str
Expand Down
12 changes: 11 additions & 1 deletion tests/unit/domain/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@

import pytest

from rubicon_ml.domain import Experiment, Feature, Metric, Parameter, Project
from rubicon_ml.domain import (
Artifact,
Dataframe,
Experiment,
Feature,
Metric,
Parameter,
Project,
)


@pytest.mark.parametrize(
["domain_cls", "required_kwargs"],
[
(Artifact, {"name": "test_domain_extra_kwargs"}),
(Dataframe, {}),
(Experiment, {"project_name": "test_domain_extra_kwargs"}),
(Feature, {"name": "test_domain_extra_kwargs"}),
(Metric, {"name": "test_domain_extra_kwargs", "value": 0.0}),
Expand Down

0 comments on commit 6b9a25a

Please sign in to comment.