-
Notifications
You must be signed in to change notification settings - Fork 12
ENH: better handling of DF -> ChoiceDataset parametrization #303
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
base: main
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
Summary of ChangesHello @VincentAuriau, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant enhancement to the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request refactors the creation of a ChoiceDataset from a wide DataFrame by replacing prefix/suffix-based parameters with a more flexible pattern-based approach. This is a good enhancement that simplifies the API. My review identifies a few critical issues, including a potential NameError due to an undefined variable and a TypeError from an extra parameter being passed. I've also suggested improvements to input validation by using ValueError instead of assert.
choice_learn/data/choice_dataset.py
Outdated
| if items_features_patterns is not None: | ||
| assert all(["*" in pattern for pattern in items_features_patterns]), ( | ||
| "items_features_patterns should all contain '*' character." | ||
| ) |
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.
The variable items_features_names is not defined within the if items_features_patterns is not None: block. This will cause a NameError at line 981 when ChoiceDataset is constructed. This appears to be a regression from the previous implementation which correctly set the feature names. You should derive items_features_names from items_features_patterns.
For example, you could add the following line before this one:
items_features_names = [p.strip("*_.") for p in items_features_patterns]
choice_learn/datasets/base.py
Outdated
| items_id=items, | ||
| shared_features_columns=shared_features_by_choice_names, | ||
| items_features_suffixes=items_features_by_choice_names, | ||
| items_features_patterns=["*_%s" % s for s in items_features_by_choice_names], | ||
| delimiter="_", |
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.
The delimiter parameter is no longer accepted by from_single_wide_df after your changes. This will cause a TypeError. Please remove it.
| items_id=items, | |
| shared_features_columns=shared_features_by_choice_names, | |
| items_features_suffixes=items_features_by_choice_names, | |
| items_features_patterns=["*_%s" % s for s in items_features_by_choice_names], | |
| delimiter="_", | |
| items_features_patterns=["*_%s" % s for s in items_features_by_choice_names], | |
| choices_column=choice_column, | |
| choice_format="items_index", |
choice_learn/data/choice_dataset.py
Outdated
| assert all(["*" in pattern for pattern in items_features_patterns]), ( | ||
| "items_features_patterns should all contain '*' character." |
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.
Using assert for input validation is not recommended as assertions can be disabled (e.g., with Python's -O flag), which would bypass this check. It's better to raise a ValueError for invalid user input.
| assert all(["*" in pattern for pattern in items_features_patterns]), ( | |
| "items_features_patterns should all contain '*' character." | |
| if not all("*" in pattern for pattern in items_features_patterns): | |
| raise ValueError("items_features_patterns should all contain '*' character.") |
choice_learn/data/choice_dataset.py
Outdated
| else: | ||
| columns = [f"{item}{delimiter}{available_items_suffix}" for item in items_id] | ||
| available_items_by_choice = df[columns].to_numpy() | ||
| elif available_items_prefix is not None: | ||
| if isinstance(available_items_prefix, list): | ||
| if not len(available_items_prefix) == len(items_id): | ||
| raise ValueError( | ||
| "You have given a list of columns for availabilities." | ||
| "We consider that it is one for each item however lenghts do not match" | ||
| ) | ||
| logging.info("You have given a list of columns for availabilities.") | ||
| logging.info("Each column will be matched to an item, given their order") | ||
| available_items_by_choice = df[available_items_prefix].to_numpy() | ||
| else: | ||
| columns = [f"{available_items_prefix}{delimiter}{item}" for item in items_id] | ||
| assert "*" in available_items_pattern, ( |
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.
Using assert for input validation is not recommended as assertions can be disabled (e.g., with Python's -O flag). It's better to raise a ValueError for invalid user input.
| else: | |
| columns = [f"{item}{delimiter}{available_items_suffix}" for item in items_id] | |
| available_items_by_choice = df[columns].to_numpy() | |
| elif available_items_prefix is not None: | |
| if isinstance(available_items_prefix, list): | |
| if not len(available_items_prefix) == len(items_id): | |
| raise ValueError( | |
| "You have given a list of columns for availabilities." | |
| "We consider that it is one for each item however lenghts do not match" | |
| ) | |
| logging.info("You have given a list of columns for availabilities.") | |
| logging.info("Each column will be matched to an item, given their order") | |
| available_items_by_choice = df[available_items_prefix].to_numpy() | |
| else: | |
| columns = [f"{available_items_prefix}{delimiter}{item}" for item in items_id] | |
| assert "*" in available_items_pattern, ( | |
| if "*" not in available_items_pattern: | |
| raise ValueError("available_items_pattern should contain '*' character.") |
Coverage Report for Python 3.10
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Coverage Report for Python 3.11
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Coverage Report for Python 3.12
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
No description provided.