From f6018c51b60976143bd52b3f2e31fc0cb363a199 Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Wed, 22 Nov 2023 21:54:50 +0300 Subject: [PATCH] Apply fixes from fixit Apply recommended fix from fixit: RewriteToLiteral: It's slower to call list() than using the empty literal, because the name list must be looked up in the global scope in case it has been rebound. --- csv_metadata_quality/app.py | 2 +- csv_metadata_quality/check.py | 6 +++--- csv_metadata_quality/experimental.py | 2 +- csv_metadata_quality/fix.py | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/csv_metadata_quality/app.py b/csv_metadata_quality/app.py index 5ab9eff..79f84be 100644 --- a/csv_metadata_quality/app.py +++ b/csv_metadata_quality/app.py @@ -85,7 +85,7 @@ def run(argv): # user should be careful to no include spaces here. exclude = args.exclude_fields.split(",") else: - exclude = list() + exclude = [] # enable transparent request cache with thirty days expiry expire_after = timedelta(days=30) diff --git a/csv_metadata_quality/check.py b/csv_metadata_quality/check.py index f0ee2c1..1f416bc 100755 --- a/csv_metadata_quality/check.py +++ b/csv_metadata_quality/check.py @@ -202,7 +202,7 @@ def agrovoc(field, field_name, drop): return # Initialize an empty list to hold the validated AGROVOC values - values = list() + values = [] # Try to split multi-value field on "||" separator for value in field.split("||"): @@ -358,7 +358,7 @@ def duplicate_items(df): if items_count_unique < items_count_total: # Create a list to hold our items while we check for duplicates - items = list() + items = [] for index, row in df.iterrows(): item_title_type_date = f"{row[title_column_name]}{row[type_column_name]}{row[date_column_name]}" @@ -539,7 +539,7 @@ def countries_match_regions(row, exclude): if row[region_column_name] is not None: regions = row[region_column_name].split("||") else: - regions = list() + regions = [] for country in countries: # Look up the UN M.49 regions for this country code. CoCo seems to diff --git a/csv_metadata_quality/experimental.py b/csv_metadata_quality/experimental.py index 269d5f2..f9c32e8 100644 --- a/csv_metadata_quality/experimental.py +++ b/csv_metadata_quality/experimental.py @@ -20,7 +20,7 @@ def correct_language(row, exclude): # Initialize some variables at global scope so that we can set them in the # loop scope below and still be able to access them afterwards. language = "" - sample_strings = list() + sample_strings = [] title = None # Iterate over the labels of the current row's values. Before we transposed diff --git a/csv_metadata_quality/fix.py b/csv_metadata_quality/fix.py index b4f9c4a..48675d1 100755 --- a/csv_metadata_quality/fix.py +++ b/csv_metadata_quality/fix.py @@ -23,7 +23,7 @@ def whitespace(field, field_name): return # Initialize an empty list to hold the cleaned values - values = list() + values = [] # Try to split multi-value field on "||" separator for value in field.split("||"): @@ -64,7 +64,7 @@ def separators(field, field_name): return # Initialize an empty list to hold the cleaned values - values = list() + values = [] # Try to split multi-value field on "||" separator for value in field.split("||"): @@ -175,7 +175,7 @@ def duplicates(field, field_name): values = field.split("||") # Initialize an empty list to hold the de-duplicated values - new_values = list() + new_values = [] # Iterate over all values for value in values: @@ -355,10 +355,10 @@ def countries_match_regions(row, exclude): if row[region_column_name] is not None: regions = row[region_column_name].split("||") else: - regions = list() + regions = [] # An empty list for our regions so we can keep track for all countries - missing_regions = list() + missing_regions = [] for country in countries: # Look up the UN M.49 regions for this country code. CoCo seems to