-
Notifications
You must be signed in to change notification settings - Fork 56
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
Add replace_subgroups
function
#215
Conversation
|
replace_subgroups
functionreplace_selections
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @zhiruiluo, interesting PR.
Left some comments. let me know what you think.
Hi @lebrice, Here is the updating:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @zhiruiluo , this is a lot clearer!
There are just a few small things to tweak, but this looks pretty good!
Co-authored-by: Fabrice Normandin <[email protected]>
Co-authored-by: Fabrice Normandin <[email protected]>
replace_selections
functionreplace_subgroups
function
Hi @lebrice, Here are some updates so far:
I would appreciate any further feedback or suggestions for improvement that you may have. Thank you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @zhiruiluo , and sorry it took so long to review this.
This looks good to me. I only have a tiny comment on the naming of one of the functions, but appart from that, this is good to merge!
Thanks again!
simple_parsing/replace.py
Outdated
>>> unflatten_selection_dict({'lv1': 'a', 'lv1.lv2': 'b', 'lv1.lv2.lv3': 'c'}) | ||
{'lv1': {'__key__': 'a', 'lv2': 'b', 'lv2.lv3': 'c'}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest making recursive=True
by default. The non-recursive case seems a bit strange to me.
Also, is this function expected to be used by users? If not, I'd prefix it with an underscore (_unflatten_selection_dict
) to signal that it is an internal function only used in this module.
I would also place it below other "public" functions like replace
and replace_subgroups
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is to add the
replace_selections
function that replaces some values in a dataclass and replaces dataclass type in nested union of dataclasses or subgroups.simple_parsing.replace_selections
function support replacingeplaces dataclass type in nested union of dataclasses or subgroups in addition tosimple_parsing.replace
#212.replace_selections(obj: DataclassT, changes_dict: dict[str, Any] | None = None, selections: dict[str, Key | DataclassT] | None = None, **changes) -> DataclassT:
simple_replace.replace
, this callsreplace_selected_dataclass
before callingsimple_parsing.replace
.replace_selected_dataclass
selections
is in flat format, e.g. {"ab_or_cd": 'cd', "ab_or_cd.c_or_d": 'd'}Key
of subgroups, dataclass type, and dataclass instance.Open question:
simple_parsing.replace_selections
andsimple_parsing.replace
?Examples