Skip to content

Commit

Permalink
fix(logic): minor logic fixes;
Browse files Browse the repository at this point in the history
- Minor logic fixes for the new `strip_extra_white` field.
  • Loading branch information
JVickery-TBS committed May 14, 2024
1 parent 50080ea commit 116c29f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ckanext/xloader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def strip_white_space_iter():
for row in super_iter():
for _index, _cell in enumerate(row):
# only strip white space if strip_extra_white is True
if fields[_index].get('strip_extra_white', True) and isinstance(_cell, str):
if fields and fields[_index].get('strip_extra_white', True) and isinstance(_cell, str):
row[_index] = _cell.strip()
yield row
stream.iter = strip_white_space_iter
Expand All @@ -243,7 +243,7 @@ def strip_white_space_iter():
for row in super_iter():
for _index, _cell in enumerate(row):
# only strip white space if strip_extra_white is True
if fields[_index].get('strip_extra_white', True) and isinstance(_cell, str):
if fields and fields[_index].get('strip_extra_white', True) and isinstance(_cell, str):
row[_index] = _cell.strip()
yield row
stream.iter = strip_white_space_iter
Expand Down Expand Up @@ -424,6 +424,10 @@ def load_table(table_filepath, resource_id, mimetype='text/csv', logger=None):
for t, h in zip(types, headers)]
for h in headers:
fields.append(existing_fields_by_headers.get(h, {}))
else:
# default strip_extra_white
for h in headers:
fields.append({'strip_extra_white': True})

headers = [header.strip()[:MAX_COLUMN_LENGTH] for header in headers if header.strip()]
type_converter = TypeConverter(types=types, fields=fields)
Expand Down Expand Up @@ -452,6 +456,10 @@ def row_iterator():
type_override = existing_info[h['id']].get('type_override')
if type_override in list(_TYPE_MAPPING.values()):
h['type'] = type_override
else:
# default strip_extra_white
for h in headers_dicts:
h['strip_extra_white'] = True

logger.info('Determined headers and types: %s', headers_dicts)

Expand Down

0 comments on commit 116c29f

Please sign in to comment.