Skip to content

🧹 Refactor: Consolidate numeric extraction into shared utility#6

Open
dhanush342 wants to merge 1 commit intomainfrom
code-health/extract-numeric-util-15683755180382661517
Open

🧹 Refactor: Consolidate numeric extraction into shared utility#6
dhanush342 wants to merge 1 commit intomainfrom
code-health/extract-numeric-util-15683755180382661517

Conversation

@dhanush342
Copy link
Copy Markdown
Owner

🎯 What: The duplicated numeric extraction logic (previously in web/streamlit_dashboard.py and evaluate_gsm8k.py) has been consolidated into a new, shared utils.py module. The function now handles non-string inputs safely by enforcing a type cast and uses robust regular expressions to extract negative numbers, fractions, and decimals consistently.

💡 Why: This improves maintainability and readability by ensuring a single source of truth for numeric extraction. If future extraction tweaks are needed, they only have to be made in one place. Additionally, redundant logic and unused imports have been cleaned up across the involved files.

Verification:

  1. Manually verified the output of test_utils.py covering standard numbers, fractions, decimals, text mixed with numbers, and missing (None) inputs.
  2. Verified web/streamlit_dashboard.py logic appropriately imports utils.py.
  3. Verified evaluate_gsm8k.py imports and uses extract_numeric seamlessly, ensuring the math evaluation logic is preserved.
  4. Cleaned up unused imports re, Fraction from both evaluate_gsm8k.py and web/streamlit_dashboard.py.
  5. Created a .gitignore to keep __pycache__ out of version control and ensure tests remain in the tests/ directory.

Result: A cleaner, deduplicated codebase with a centralized, robust utility function for extracting math answers.


PR created automatically by Jules for task 15683755180382661517 started by @dhanush342

Co-authored-by: dhanush342 <187305764+dhanush342@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings March 18, 2026 00:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR centralizes numeric-answer extraction by moving duplicated parsing logic into a shared utils.extract_numeric() helper, and updates the evaluation script(s) to use it.

Changes:

  • Added utils.py with shared extract_numeric() implementation.
  • Updated evaluate_gsm8k.py and web/streamlit_dashboard.py to use the shared helper (and removed the local implementations/imports).
  • Added a small test script and a .gitignore entry for Python bytecode.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
web/streamlit_dashboard.py Removes local numeric parsing; imports extract_numeric (and adds a runtime sys.path tweak).
utils.py Introduces shared extract_numeric() utility using regex + Fraction.
tests/test_utils.py Adds coverage script for common numeric extraction cases.
evaluate_gsm8k.py Replaces bespoke parse_numeric() with utils.extract_numeric().
.gitignore Ignores __pycache__ and *.pyc.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +6 to 11
import sys
import os

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from utils import extract_numeric
from inference import generate_solution
import sys
import os

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants