From 7cfd4c0b59e2a792ceb959eb0bd92fe3a7a1eac8 Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Tue, 6 Oct 2020 17:11:39 +0300 Subject: [PATCH] csv_metadata_quality: Move scoped imports to global According to PEP8 we should avoid scoped imports unless you have a good reason. Here there are two cases where we do (issn and isbn), but I will move the others to the global scope. --- csv_metadata_quality/check.py | 12 +++++------- csv_metadata_quality/fix.py | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/csv_metadata_quality/check.py b/csv_metadata_quality/check.py index f54a516..4336dcd 100755 --- a/csv_metadata_quality/check.py +++ b/csv_metadata_quality/check.py @@ -1,4 +1,9 @@ +from datetime import datetime, timedelta + import pandas as pd +import requests +import requests_cache +from pycountry import languages def issn(field): @@ -85,7 +90,6 @@ def date(field, field_name): Prints the date if invalid. """ - from datetime import datetime if pd.isna(field): print(f"Missing date ({field_name}).") @@ -170,8 +174,6 @@ def language(field): Prints the value if it is invalid. """ - from pycountry import languages - # Skip fields with missing values if pd.isna(field): return @@ -213,10 +215,6 @@ def agrovoc(field, field_name): Prints a warning if the value is invalid. """ - from datetime import timedelta - import requests - import requests_cache - # Skip fields with missing values if pd.isna(field): return diff --git a/csv_metadata_quality/fix.py b/csv_metadata_quality/fix.py index 8d729b1..c2c232d 100755 --- a/csv_metadata_quality/fix.py +++ b/csv_metadata_quality/fix.py @@ -1,7 +1,10 @@ import re +from unicodedata import normalize import pandas as pd +from csv_metadata_quality.util import is_nfc + def whitespace(field, field_name): """Fix whitespace issues. @@ -212,9 +215,6 @@ def normalize_unicode(field, field_name): Return normalized string. """ - from csv_metadata_quality.util import is_nfc - from unicodedata import normalize - # Skip fields with missing values if pd.isna(field): return