Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tools/import_validation/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ def _load_differ_df_from_mcf(self, input_dir: str) -> pd.DataFrame:
stats[current_var][diff_type] += 1

if not stats:
return pd.DataFrame()
return pd.DataFrame(
columns=['StatVar', 'ADDED', 'DELETED', 'MODIFIED'])

rows = []
for var, counts in stats.items():
Expand Down
6 changes: 5 additions & 1 deletion tools/statvar_importer/mcf_file_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ def normalize_list(value: str, sort: bool = True) -> str:
value_list = get_value_list(value)
has_quotes = True
else:
value_list = value.split(',')
value_list = [v.strip() for v in value.split(',')]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the normalize_value() call below does remove extra namespace and other normalizations too like namespaces. this can be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalize_value() strips, but it runs after sort(). Without stripping here, leading spaces alter the sort order and break our golden files

values = []
if sort:
value_list = sorted(value_list)
Expand Down Expand Up @@ -931,6 +931,10 @@ def normalize_value(
if value[0] == '"' and value[-1] == '"' and len(value) > 100:
# Retain very long strings, such as geoJsonCoordinates, as is.
return value
if value.startswith('[') and value.endswith(']') and ',' in value:
Comment thread
niveditasing marked this conversation as resolved.
inner_list = value[1:-1].strip()
normalized_list = normalize_list(inner_list)
return f'[{normalized_list}]'
if ',' in value and maybe_list:
return normalize_list(value)
if value[0] == '[':
Expand Down
15 changes: 15 additions & 0 deletions tools/statvar_importer/mcf_file_util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ def test_normalize_range(self):
self.assertEqual('dcid:Upto20',
mcf_file_util.normalize_value('[ - 20 ]', True))

def test_normalize_value_list_with_brackets(self):
# Test bracketed lists of values with commas.
self.assertEqual(
'[dcid:A,dcid:B]',
mcf_file_util.normalize_value('[dcid:B,dcid:A]'),
)
self.assertEqual(
'[dcid:A,dcid:B]',
mcf_file_util.normalize_value('[ dcid:B, dcid:A ]'),
)
self.assertEqual(
'["ValueA","ValueB"]',
mcf_file_util.normalize_value('[ "ValueB", "ValueA" ]'),
)

def test_load_mcf_file(self):
mcf_nodes = mcf_file_util.load_mcf_nodes(
os.path.join(_module_dir_, 'test_data',
Expand Down
Loading