Skip to content

Commit

Permalink
types fixup for #25
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzoic committed Sep 8, 2023
1 parent c3b367c commit 00fd51a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
4 changes: 2 additions & 2 deletions countess/core/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ class PandasTransformSingleToTuplePlugin(
):
"""Transformer which takes a single column and returns a tuple of values"""

def process_value(self, value, logger: Logger):
def process_value(self, value, logger: Logger) -> Optional[Iterable]:
raise NotImplementedError(f"{self.__class__}.process_value()")


Expand All @@ -462,7 +462,7 @@ class PandasTransformSingleToDictPlugin(
):
"""Transformer which takes a single column and returns a dictionary of values"""

def process_value(self, value, logger: Logger):
def process_value(self, value, logger: Logger) -> Optional[Dict]:
raise NotImplementedError(f"{self.__class__}.process_value()")


Expand Down
9 changes: 3 additions & 6 deletions countess/plugins/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ def process_dataframe(self, dataframe: pd.DataFrame, logger: Logger) -> pd.DataF
assert isinstance(self.parameters["output"], ArrayParam)
df = super().process_dataframe(dataframe, logger)

#if self.parameters["drop_unmatch"].value:
# output_names = [pp.name.value for pp in self.parameters["output"]]
# df = df.dropna(subset=output_names, how="all")

if self.parameters["drop_column"].value:
column_name = self.parameters["column"].value
if column_name in df.columns:
Expand All @@ -75,7 +71,7 @@ def process_dataframe(self, dataframe: pd.DataFrame, logger: Logger) -> pd.DataF

return df

def process_value(self, value: str, logger: Logger) -> Iterable:
def process_value(self, value: str, logger: Logger) -> Optional[Iterable]:
assert self.compiled_re is not None
assert isinstance(self.parameters["output"], ArrayParam)
if value is not None:
Expand All @@ -90,7 +86,7 @@ def process_value(self, value: str, logger: Logger) -> Iterable:
# If dropping unmatched values, return a simple None which will
# be filtered out in series_to_dataframe below, otherwise return
# a tuple of Nones which will fill in the unmatched row.

if self.parameters["drop_unmatch"].value:
return None
else:
Expand All @@ -103,6 +99,7 @@ def series_to_dataframe(self, series: pd.Series) -> pd.DataFrame:
series.dropna(inplace=True)
return super().series_to_dataframe(series)


class RegexReaderPlugin(PandasInputPlugin):
name = "Regex Reader"
description = "Loads arbitrary data from line-delimited files"
Expand Down

0 comments on commit 00fd51a

Please sign in to comment.