Skip to content
Snippets Groups Projects

WIP: #45 - WTO: Write datasets in JSON repo for "annually" category

Closed Bruno Duyé requested to merge dev into master
All threads resolved!
1 file
+ 5
5
Compare changes
  • Side-by-side
  • Inline
+ 5
5
@@ -281,7 +281,7 @@ def create_dataset_and_series(dataset, parent_category_path):
elif filename.endswith('.xls'):
create_dataset_and_series_from_xls(dataset, dataset_path)
else:
raise ValueError("Unexpected file format: {} for dataset \"{}\"".format(filename, dataset['name']))
raise ValueError("Unexpected file format: {} for dataset {!r}".format(filename, dataset['name']))
def create_dataset_and_series_from_csv(dataset, dataset_path):
@@ -453,7 +453,7 @@ def create_dataset_and_series_from_xls(dataset, dataset_path):
assert value, "Unexpected empty cell at position {} ({}) in {} sheet".format(
row_coords, xlrd.cellname(*row_coords), sheet.name)
assert re.match(period_regexp, value), \
"Unexpected period \"{}\" at position {} ({}) in {} sheet".format(
"Unexpected period {!r} at position {} ({}) in {} sheet".format(
value, row_coords, xlrd.cellname(*row_coords), sheet.name)
return first_non_empty_cell_col_number, periods_row
@@ -488,14 +488,14 @@ def create_dataset_and_series_from_xls(dataset, dataset_path):
continue
# Stop parsing if dataset defines a "stop_text" and this text is found in row
if dataset.get('stop_text') and dataset.get('stop_text') in row:
print("Info: reached stop text \"{}\" at line {}".format(dataset.get('stop_text'), row_num))
print("Info: reached stop text {!r} at line {}".format(dataset.get('stop_text'), row_num))
break
# Parse data rows
region_code = row[xls_constants['regions_codes_col_num']].strip()
region_label = row[xls_constants['regions_labels_col_num']].strip()
# Pass through rows without data
if set(row[first_value_col_num:]) == {''}:
print("Info: row {} - ignoring {}".format(row_num, "\"{}\"".format(region_label)
print("Info: row {} - ignoring {}".format(row_num, "{!r}".format(region_label)
if region_label else "line {}".format(row_num)))
continue
assert region_label, "No region label found at row {}".format(row_num)
@@ -508,7 +508,7 @@ def create_dataset_and_series_from_xls(dataset, dataset_path):
v_, error = to_float(value)
if error:
row_coords = (row_num, first_value_col_num + i)
assert not error, "Unexpected value \"{}\" at position {} ({}) in sheet \"{}\"".format(
assert not error, "Unexpected value {!r} at position {} ({}) in sheet {!r}".format(
value, row_coords, xlrd.cellname(*row_coords), sheet.name)
else:
converted_values.append(str(value))