Skip to content

Fix a bug with custom attribute name clashes #590

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

Merged
merged 2 commits into from
Feb 15, 2020

Conversation

BenjaminBossan
Copy link
Collaborator

When a user adds a new "settable" attribute (i.e. that works with
set_params) whose names starts the same as an existing attribute (say
"optimizer_2"), and adds a corresponding argument (say
"optimizer_2__lr"), skorch will erroneously complain about this
argument because it thinks it belongs to the other
attribute ("optimizer" in this example). The added unit test should
illustrate this behavior.

When a user adds a new "settable" attribute (i.e. that works with
set_params) whose names starts the same as an existing attribute (say
"optimizer_2"), and adds a corresponding argument (say
"optimizer_2__lr"), skorch will erroneously complain about this
argument because it thinks it belongs to the other
attribute ("optimizer" in this example). The added unit test should
illustrate this behavior.
@@ -1334,7 +1334,7 @@ def _check_kwargs(self, kwargs):
for key in kwargs:
if key.endswith('_'):
continue
for prefix in self.prefixes_:
for prefix in sorted(self.prefixes_, key=lambda s: (-len(s), s)):
Copy link
Member

Choose a reason for hiding this comment

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

For future maintainability, add a comment about why this sorting is needed or at least a link to this issue. (It is not obvious at first glance why this is needed)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a comment

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

LGTM

@BenjaminBossan BenjaminBossan merged commit 9db322a into master Feb 15, 2020
sthagen added a commit to sthagen/skorch-dev-skorch that referenced this pull request Feb 16, 2020
Fix a bug with custom attribute name clashes (skorch-dev#590)
@BenjaminBossan BenjaminBossan deleted the bugfix-custom-attribute-name-clash branch February 16, 2020 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants