Skip to content

Commit

Permalink
delete unused match_substring function
Browse files Browse the repository at this point in the history
  • Loading branch information
dougiesquire committed Jun 27, 2023
1 parent 8997714 commit 867f1f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 30 deletions.
37 changes: 7 additions & 30 deletions src/access_nri_intake/catalog/translators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 76 in src/access_nri_intake/catalog/translators.py

View check run for this annotation

Codecov / codecov/patch

src/access_nri_intake/catalog/translators.py#L76

Added line #L76 was not covered by tests
else:
return series
except KeyError:
Expand Down Expand Up @@ -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"])

Check warning on line 169 in src/access_nri_intake/catalog/translators.py

View check run for this annotation

Codecov / codecov/patch

src/access_nri_intake/catalog/translators.py#L169

Added line #L169 was not covered by tests

def _realm_translator(self):
"""
Expand All @@ -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"])

Check warning on line 187 in src/access_nri_intake/catalog/translators.py

View check run for this annotation

Codecov / codecov/patch

src/access_nri_intake/catalog/translators.py#L187

Added line #L187 was not covered by tests


class Cmip5Translator(DefaultTranslator):
Expand Down Expand Up @@ -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"])

Check warning on line 217 in src/access_nri_intake/catalog/translators.py

View check run for this annotation

Codecov / codecov/patch

src/access_nri_intake/catalog/translators.py#L217

Added line #L217 was not covered by tests

def _realm_translator(self):
"""
Expand All @@ -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"])

Check warning on line 235 in src/access_nri_intake/catalog/translators.py

View check run for this annotation

Codecov / codecov/patch

src/access_nri_intake/catalog/translators.py#L235

Added line #L235 was not covered by tests


class EraiTranslator(DefaultTranslator):
Expand All @@ -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"])

Check warning on line 262 in src/access_nri_intake/catalog/translators.py

View check run for this annotation

Codecov / codecov/patch

src/access_nri_intake/catalog/translators.py#L262

Added line #L262 was not covered by tests


def _cmip_frequency_translator(df):
Expand Down Expand Up @@ -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
Expand All @@ -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))
File renamed without changes.

0 comments on commit 867f1f1

Please sign in to comment.