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

Support property attributes in repr of BaseMixin #469

Merged
merged 5 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
-

### Changed
-
- Add support of property attributes in `__repr__` of `BaseMixin` ([#469](https://github.com/etna-team/etna/pull/469))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not only __repr__, but also to_dict.

-
-
-
Expand Down
6 changes: 3 additions & 3 deletions etna/core/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def __repr__(self):
if param.kind == param.VAR_POSITIONAL:
continue
elif param.kind == param.VAR_KEYWORD:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create some basic tests on working with BaseMixin. The methods to functionality to check is:

  • repr
    • Add test on dummy class with private attribute and public property
  • to_dict
    • We already have file test_to_dict, let's add new tests here
    • Add test on dummy class with private attribute and public property
  • set_params
    • We already have file test_set_params, let's add new tests here
    • Add test on dummy class with private attribute and public property

for arg_, value in self.__dict__[arg].items():
for arg_, value in getattr(self, arg).items():
args_str_representation += f"{arg_} = {repr(value)}, "
else:
try:
value = self.__dict__[arg]
value = getattr(self, arg)
except KeyError as e:
value = None
warnings.warn(f"You haven't set all parameters inside class __init__ method: {e}")
Expand Down Expand Up @@ -90,7 +90,7 @@ def to_dict(self):
init_parameters = self._get_init_parameters()
params = {}
for arg in init_parameters.keys():
value = self.__dict__[arg]
value = getattr(self, arg)
if value is None:
continue
params[arg] = BaseMixin._parse_value(value=value)
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ filterwarnings = [
"ignore: Given top_k=.* is less than n_segments=.*. Algo will filter data without Gale-Shapley run.",
"ignore: This model doesn't work with exogenous features",
"ignore: Some of external objects in input parameters could be not",
"ignore: You haven't set all parameters inside class __init__ method.* 'is_freezed'",
# external warnings
"ignore: Attribute 'logging_metrics' is an instance of `nn.Module` and is already",
"ignore: Attribute 'loss' is an instance of `nn.Module` and is already",
Expand Down
Loading