Added support for data masking in Average, Accuracy and MultiMetric#5332
Added support for data masking in Average, Accuracy and MultiMetric#5332copybara-service[bot] merged 1 commit intomainfrom
Conversation
Summary of ChangesHello, 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 re-introduces and refines data masking capabilities for key metric classes ( 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. Changelog
Activity
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.
Code Review
This pull request adds support for data masking in the Average, Accuracy, and MultiMetric metrics. The changes for Average and Accuracy are well-implemented, and the accompanying tests are thorough. However, I've identified a potential issue in MultiMetric.update where providing a global mask could lead to a TypeError if a sub-metric doesn't support masking. I've included a detailed comment with a suggested fix for this issue.
| metric_mask_kwarg = {} | ||
| metric_mask = mask.get(metric_name, None) if isinstance(mask, dict) else mask | ||
| if metric_mask is not None: | ||
| metric_mask_kwarg = {"mask": metric_mask} | ||
| getattr(self, metric_name).update(**(updates | metric_mask_kwarg)) |
There was a problem hiding this comment.
The current implementation for handling masks in MultiMetric.update can lead to a TypeError if a global mask is provided and one of the sub-metrics does not accept a mask keyword argument. The mask is unconditionally added to the keyword arguments passed to the sub-metric's update method.
To make this more robust, we should check if the sub-metric's update method actually accepts a mask argument before adding it. This can be done using inspect.signature.
metric_update = getattr(self, metric_name).update
metric_mask = mask.get(metric_name, None) if isinstance(mask, dict) else mask
kwargs = updates
if metric_mask is not None:
import inspect
sig = inspect.signature(metric_update)
if 'mask' in sig.parameters or any(p.kind == inspect.Parameter.VAR_KEYWORD for p in sig.parameters.values()):
kwargs = {**updates, 'mask': metric_mask}
metric_update(**kwargs)
Try to reland reverted #5326
fixing reported error in the 3rd party repos