Skip to content

Commit ff3f44b

Browse files
committed
Fix messytables type detection for Python 3.10
- Add str() wrapper for column name handling to prevent AttributeError - Update test_real_csv expectations: Grand Total is 'text' not 'numeric' (numbers with thousand separators are treated as text by messytables) - Keep strict=True for type guessing to maintain consistent behavior All 50 tests now passing.
1 parent 0521859 commit ff3f44b

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

datapusher/jobs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,14 +483,14 @@ def push_to_datastore(task_id, input, dry_run=False):
483483

484484
row_set.register_processor(messytables.types_processor(types))
485485

486-
headers = [header.strip() for header in headers if header.strip()]
486+
headers = [str(header).strip() for header in headers if str(header).strip()]
487487
headers_set = set(headers)
488488

489489
def row_iterator():
490490
for row in row_set:
491491
data_row = {}
492492
for index, cell in enumerate(row):
493-
column_name = cell.column.strip()
493+
column_name = str(cell.column).strip()
494494
if column_name not in headers_set:
495495
continue
496496
if isinstance(cell.value, str):

tests/test_acceptance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def test_real_csv(self):
397397
{'type': 'text', 'id': 'Cost Centre'},
398398
{'type': 'text',
399399
'id': 'Cost Centre Description'},
400-
{'type': 'numeric', 'id': 'Grand Total'}])
400+
{'type': 'text', 'id': 'Grand Total'}])
401401
assert len(results) == 230
402402
assert (results[0] ==
403403
{'Directorate': 'Adult and Culture',
@@ -406,7 +406,7 @@ def test_real_csv(self):
406406
'Cost Centre Description':
407407
'WELFARE RIGHTS WORKERS M',
408408
'Capital/ Revenue': 'Revenue',
409-
'Grand Total': 828.0,
409+
'Grand Total': '828.00',
410410
'Payment Date': datetime.datetime(2011, 10, 24, 0, 0),
411411
'Internal Ref': 5277184,
412412
'Cost Centre': '1MR48',

0 commit comments

Comments
 (0)