Skip to content

refactor: stop mutating inputs in extraction pipeline #199

Description

@boscorat

Parent issue

#194 — function purification

Problem

Three functions silently mutate their inputs:

  1. get_standard_fields (statement_functions.py:775) — mutates the caller's checks_and_balances DataFrame in-place via hstack(..., in_place=True) (lines 890-891, 900, 902-903, 905). This is the most problematic — the caller's DataFrame is silently modified.

  2. extract_fields (statement_functions.py:314) — mutates location.top_left coordinates in-place (line 354-355) and mutates results DataFrame via vstack(in_place=True) (lines 401, 489, 566).

  3. get_table_from_region (pdf_functions.py:109) — mutates location.top_left and location.bottom_right in-place (lines 167-168) and mutates vertical_lines list in-place (lines 152-153, 157-159, 175).

Proposal

  • get_standard_fields should return a tuple (data, updated_checks_and_balances) instead of mutating in-place.
  • extract_fields should work on copies of location and return new coordinates.
  • get_table_from_region should accept a copy of vertical_lines and return updated coordinates instead of mutating.

Code relationships

Target functions:

  • get_standard_fields()statement_functions.py:775
  • extract_fields()statement_functions.py:314
  • get_table_from_region()pdf_functions.py:109

Callers (will need updating):

  • get_results()statement_functions.py:688 (calls all three)
  • Statement.get_results()statements.py:631 (calls module-level get_results)

Related (pass mutated objects):

  • Location dataclass — data.py (the object being mutated)
  • spawn_locations()statement_functions.py:77 (produces Location objects that get mutated)

Existing tests

None. None of these functions have direct test coverage. Refactoring will not break any existing tests.

Siblings

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorcode refactoring

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions