From 867f1f1f63b3cbcd4b54cb4e73163433095efe60 Mon Sep 17 00:00:00 2001 From: dougiesquire Date: Tue, 27 Jun 2023 16:08:17 +1000 Subject: [PATCH] delete unused match_substring function --- src/access_nri_intake/catalog/translators.py | 37 ++++--------------- ..._builder_utils.py => test_source_utils.py} | 0 2 files changed, 7 insertions(+), 30 deletions(-) rename tests/{test_builder_utils.py => test_source_utils.py} (100%) diff --git a/src/access_nri_intake/catalog/translators.py b/src/access_nri_intake/catalog/translators.py index f2d85de..b7a55e6 100644 --- a/src/access_nri_intake/catalog/translators.py +++ b/src/access_nri_intake/catalog/translators.py @@ -73,7 +73,7 @@ def _default_translator(self, column): if column in self.source.esmcat.columns_with_iterables: return series.apply(tuple) elif column in COLUMNS_WITH_ITERABLES: - return to_tuple(series) + return _to_tuple(series) else: return series except KeyError: @@ -166,7 +166,7 @@ def _model_translator(self): """ Return model from source_id """ - return to_tuple(self.source.df["source_id"]) + return _to_tuple(self.source.df["source_id"]) def _realm_translator(self): """ @@ -184,7 +184,7 @@ def _variable_translator(self): """ Return variable as a tuple """ - return to_tuple(self.source.df["variable_id"]) + return _to_tuple(self.source.df["variable_id"]) class Cmip5Translator(DefaultTranslator): @@ -214,7 +214,7 @@ def _model_translator(self): """ Return variable as a tuple """ - return to_tuple(self.source.df["model"]) + return _to_tuple(self.source.df["model"]) def _realm_translator(self): """ @@ -232,7 +232,7 @@ def _variable_translator(self): """ Return variable as a tuple """ - return to_tuple(self.source.df["variable"]) + return _to_tuple(self.source.df["variable"]) class EraiTranslator(DefaultTranslator): @@ -259,7 +259,7 @@ def _variable_translator(self): """ Return variable as a tuple """ - return to_tuple(self.source.df["variable"]) + return _to_tuple(self.source.df["variable"]) def _cmip_frequency_translator(df): @@ -311,7 +311,7 @@ def _parse(string): return df["realm"].apply(lambda string: _parse(string)) -def to_tuple(series): +def _to_tuple(series): """ Make entries in the provided series a tuple @@ -321,26 +321,3 @@ def to_tuple(series): A pandas Series or another object with an `apply` method """ return series.apply(lambda x: (x,)) - - -def match_substrings(series, substrings): - """ - Search for a list of substrings in each entry, ignoring case, and return the - one that's found. - - Parameters - ---------- - series: :py:class:`~pandas.Series` - A pandas Series or another object with an `apply` method - substrings: list of str - A list of substrings to try and match on each entry in series - """ - - def _parse(s): - for substring in substrings: - match = re.match(rf".*{substring}.*", s, flags=re.IGNORECASE) - if match: - return substring - raise ValueError(f"Could not match {s} to any substring") - - return series.apply(lambda s: _parse(s)) diff --git a/tests/test_builder_utils.py b/tests/test_source_utils.py similarity index 100% rename from tests/test_builder_utils.py rename to tests/test_source_utils.py