Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remaining dataclasses - warn on extra kwargs #476

Merged
merged 6 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exclude_lines =
raise AssertionError
raise NotImplementedError
if __name__ == .__main__.:
if TYPE_CHECKING:
omit =
versioneer.py
rubicon_ml/_version.py
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 []
70 changes: 58 additions & 12 deletions rubicon_ml/domain/feature.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,64 @@
from dataclasses import dataclass, field
from datetime import datetime
from typing import List, Optional
from dataclasses import dataclass
from typing import TYPE_CHECKING, List, Optional

from rubicon_ml.domain.mixin import CommentMixin, TagMixin
from rubicon_ml.domain.utils import uuid
from rubicon_ml.domain.mixin import CommentMixin, InitMixin, TagMixin

if TYPE_CHECKING:
from datetime import datetime

@dataclass
class Feature(TagMixin, CommentMixin):
name: str

id: str = field(default_factory=uuid.uuid4)
@dataclass(init=False)
class Feature(CommentMixin, InitMixin, TagMixin):
"""A domain-level feature.

name : str
The feature's name.
comments : list of str, optional
Additional text information and observations about the feature. Defaults to
`None`.
created_at : datetime, optional
The date and time the feature 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 feature. Defaults to `None`.
id : str, optional
The feature'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.
importance : float, optional
The feature's calculated importance value. Defaults to `None`.
tags : list of str, optional
The values this feature 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
importance: Optional[float] = None
tags: List[str] = field(default_factory=list)
comments: List[str] = field(default_factory=list)
created_at: datetime = field(default_factory=datetime.utcnow)
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,
importance: Optional[float] = None,
tags: Optional[List[str]] = None,
**kwargs,
):
"""Initialize this domain feature."""

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.importance = importance
self.tags = tags or []
86 changes: 68 additions & 18 deletions rubicon_ml/domain/metric.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,75 @@
from dataclasses import dataclass, field
from datetime import datetime
from typing import List, Optional
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, List, Literal, Optional

from rubicon_ml.domain.mixin import CommentMixin, TagMixin
from rubicon_ml.domain.utils import uuid
from rubicon_ml.domain.mixin import CommentMixin, InitMixin, TagMixin

if TYPE_CHECKING:
from datetime import datetime

DIRECTIONALITY_VALUES = ["score", "loss"]


@dataclass
class Metric(TagMixin, CommentMixin):
name: str
value: float
@dataclass(init=False)
class Metric(CommentMixin, InitMixin, TagMixin):
"""A domain-level metric.

id: str = field(default_factory=uuid.uuid4)
name : str
The metric's name.
value : any
The metric's value.
comments : list of str, optional
Additional text information and observations about the metric. Defaults to
`None`.
created_at : datetime, optional
The date and time the metric 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 metric. Defaults to `None`.
directionality : "score" or "loss", optional
"score" to indicate greater values are better, "loss" to indiciate smaller
values are better. Defaults to "score".
id : str, optional
The metric'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.
tags : list of str, optional
The values this metric is tagged with. Defaults to `None`.
"""

name: str
value: Any
comments: Optional[List[str]] = None
created_at: Optional["datetime"] = None
description: Optional[str] = None
directionality: str = "score"
created_at: datetime = field(default_factory=datetime.utcnow)
tags: List[str] = field(default_factory=list)
comments: List[str] = field(default_factory=list)

def __post_init__(self):
if self.directionality not in DIRECTIONALITY_VALUES:
raise ValueError(f"metric directionality must be one of {DIRECTIONALITY_VALUES}")
directionality: Literal["score", "loss"] = "score"
id: Optional[str] = None
tags: Optional[List[str]] = None

def __init__(
self,
name: str,
value: Any,
comments: Optional[List[str]] = None,
created_at: Optional["datetime"] = None,
description: Optional[str] = None,
directionality: Literal["score", "loss"] = "score",
id: Optional[str] = None,
tags: Optional[List[str]] = None,
**kwargs,
):
"""Initialize this domain metric."""

if directionality not in DIRECTIONALITY_VALUES:
raise ValueError(f"`directionality` must be one of {DIRECTIONALITY_VALUES}")

self._check_extra_kwargs(kwargs)

self.name = name
self.value = value
self.comments = comments or []
self.created_at = self._init_created_at(created_at)
self.description = description
self.directionality = directionality
self.id = self._init_id(id)
self.tags = tags or []
Loading
Loading