Skip to content

Refactor transaction extraction and clean up regex logic - #24

Open
rager306 wants to merge 1 commit into
mainfrom
review-fix-transaction-extraction-3380125266275653541
Open

Refactor transaction extraction and clean up regex logic#24
rager306 wants to merge 1 commit into
mainfrom
review-fix-transaction-extraction-3380125266275653541

Conversation

@rager306

@rager306 rager306 commented Jan 30, 2026

Copy link
Copy Markdown
Owner

This PR addresses issues found during code review.

  1. Fix Transaction Extraction: The extract_transactions function had a flaw where if a line was assumed to be a User ID (fallback) but didn't match the strict User ID regex or Amount regex, the parser would stop extracting amounts for that transaction. This caused transactions with non-standard User IDs (e.g. 9 digits) to have empty amounts. The fix unifies the amount extraction logic to run in all cases.
  2. Clean up PyMuPDF Parser: Removed a heuristic check that was effectively dead code (re.match for hyphens on a digits-only string).
  3. Regression Test: Added a test case test_extract_transactions_with_9_digit_user_id to tests/test_utils.py to ensure the fix works and prevents regression.

PR created automatically by Jules for task 3380125266275653541 started by @rager306

Summary by CodeRabbit

  • Bug Fixes

    • Improved account number extraction from PDF documents by simplifying the extraction process for enhanced accuracy and consistency.
    • Enhanced transaction extraction logic to handle diverse transaction scenarios more reliably, reducing processing complexity while maintaining data integrity.
  • Tests

    • Added regression test to ensure correct handling of transactions containing 9-digit user identifiers.

✏️ Tip: You can customize this high-level summary in your review settings.

- Update `pdfparser/utils.py` to fix a bug where non-standard (e.g., 9-digit) user IDs caused transaction amount extraction to fail. The fallback logic now correctly proceeds to parse debit, credit, and balance fields.
- Remove dead code in `pdfparser/pymupdf_parser.py` that checked for date patterns in account numbers using an impossible regex match.
- Add regression test for 9-digit user ID extraction in `tests/test_utils.py`.

Co-authored-by: rager306 <248269686+rager306@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.

@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown

Walkthrough

This change simplifies account number extraction in PDF parsing by removing a date-pattern guard, and refactors transaction extraction logic to more explicitly handle user ID detection and streamline credit/balance field parsing. A regression test validates the 9-digit user ID scenario.

Changes

Cohort / File(s) Summary
PDF Parser Account Extraction
pdfparser/pymupdf_parser.py
Removes date-pattern guard for account_no assignment, now unconditionally setting account_no when a 10–16 digit sequence is found in the filename.
Transaction Extraction Logic
pdfparser/utils.py
Inverts branching logic in extract_transactions to explicitly check if the next field is an amount (indicating no user ID) versus treating it as a user ID; streamlines credit and balance extraction by directly locating the next non-empty line, removing intermediate blank-line loops.
Regression Test
tests/test_utils.py
Adds test_extract_transactions_with_9_digit_user_id to verify correct handling of 9-digit user IDs in transaction extraction.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly reflects the main objectives: refactoring transaction extraction logic and cleaning up regex patterns in the PyMuPDF parser.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch review-fix-transaction-extraction-3380125266275653541

Tip

🧪 Unit Test Generation v2 is now available!

We have significantly improved our unit test generation capabilities.

To enable: Add this to your .coderabbit.yaml configuration:

reviews:
  finishing_touches:
    unit_tests:
      enabled: true

Try it out by using the @coderabbitai generate unit tests command on your code files or under ✨ Finishing Touches on the walkthrough!

Have feedback? Share your thoughts on our Discord thread!


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant