Parent issue
#194 — function purification
Problem
Three functions silently mutate their inputs:
-
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.
-
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).
-
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
Parent issue
#194 — function purification
Problem
Three functions silently mutate their inputs:
get_standard_fields(statement_functions.py:775) — mutates the caller'schecks_and_balancesDataFrame in-place viahstack(..., in_place=True)(lines 890-891, 900, 902-903, 905). This is the most problematic — the caller's DataFrame is silently modified.extract_fields(statement_functions.py:314) — mutateslocation.top_leftcoordinates in-place (line 354-355) and mutatesresultsDataFrame viavstack(in_place=True)(lines 401, 489, 566).get_table_from_region(pdf_functions.py:109) — mutateslocation.top_leftandlocation.bottom_rightin-place (lines 167-168) and mutatesvertical_lineslist in-place (lines 152-153, 157-159, 175).Proposal
get_standard_fieldsshould return a tuple(data, updated_checks_and_balances)instead of mutating in-place.extract_fieldsshould work on copies oflocationand return new coordinates.get_table_from_regionshould accept a copy ofvertical_linesand return updated coordinates instead of mutating.Code relationships
Target functions:
get_standard_fields()—statement_functions.py:775extract_fields()—statement_functions.py:314get_table_from_region()—pdf_functions.py:109Callers (will need updating):
get_results()—statement_functions.py:688(calls all three)Statement.get_results()—statements.py:631(calls module-levelget_results)Related (pass mutated objects):
Locationdataclass —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