From 0cf0bc97f0649b1362d18a8fa700c40ecf94f54f Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Wed, 3 Aug 2022 20:49:45 +0300 Subject: [PATCH] csv_metadata_quality/fix.py: fix logic error again It seems there was another logic error raised by the test in pytest. With my real data, it was enough to check if the region column was None, but with my test I was explicitly setting the region to "" (an empty string). So to be really sure we should check if the string is not None *and* if its length is greater than 0. --- csv_metadata_quality/fix.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/csv_metadata_quality/fix.py b/csv_metadata_quality/fix.py index 04b4cab..cebf47b 100755 --- a/csv_metadata_quality/fix.py +++ b/csv_metadata_quality/fix.py @@ -361,10 +361,11 @@ def countries_match_regions(row): ) # Add the missing regions back to the row, paying attention to whether - # or not the row's regions are blank or not. - if row[region_column_name] is not None: - row[region_column_name] = row[region_column_name] + "||" + "||".join( - missing_regions + # or not the row's region column is None (aka null) or just an empty + # string (length would be 0). + if row[region_column_name] is not None and len(row[region_column_name]) > 0: + row[region_column_name] = ( + row[region_column_name] + "||" + "||".join(missing_regions) ) else: row[region_column_name] = "||".join(missing_regions)