Skip to content

Commit

Permalink
fix(logic): strip white space;
Browse files Browse the repository at this point in the history
- Condition stripping on `str` type.
  • Loading branch information
JVickery-TBS committed May 8, 2024
1 parent 860ca9e commit 88f96a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 8 additions & 2 deletions ckanext/xloader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,20 @@ def load_csv(csv_filepath, resource_id, mimetype='text/csv', logger=None):
skip_rows=skip_rows) as stream:
for row in stream:
for _index, _cell in enumerate(row):
row[_index] = str(_cell).strip() # strip white space around cell values
if isinstance(_cell, str):
# strip white space around cell values
#TODO: condition behind DataDictionary option??
row[_index] = _cell.strip()
stream.save(**save_args) # have to save inside of the tabulator stream iterator
except (EncodingError, UnicodeDecodeError):
with Stream(csv_filepath, format=file_format, encoding=SINGLE_BYTE_ENCODING,
skip_rows=skip_rows) as stream:
for row in stream:
for _index, _cell in enumerate(row):
row[_index] = str(_cell).strip() # strip white space around cell values
if isinstance(_cell, str):
# strip white space around cell values
#TODO: condition behind DataDictionary option??
row[_index] = _cell.strip()
stream.save(**save_args) # have to save inside of the tabulator stream iterator
csv_filepath = f_write.name

Expand Down
7 changes: 5 additions & 2 deletions ckanext/xloader/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ def convert_types(self, extended_rows):
for cell_index, cell_value in enumerate(row):
if cell_value is None:
row[cell_index] = ''
cell_value = str(cell_value).strip() # strip white space around cell values
row[cell_index] = str(cell_value).strip() # strip white space around cell values
if isinstance(cell_value, str):
# strip white space around cell values
#TODO: condition behind DataDictionary option??
cell_value = cell_value.strip()
row[cell_index] = cell_value.strip()
if not cell_value:
continue
cell_type = self.types[cell_index] if self.types else None
Expand Down

0 comments on commit 88f96a8

Please sign in to comment.