Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzoic committed Jul 9, 2023
1 parent 4bcfb37 commit d9577b6
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 18 deletions.
20 changes: 14 additions & 6 deletions countess/core/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@
import os.path
import sys
from collections.abc import Mapping, MutableMapping
from typing import Any, Iterable, Optional, Union, Dict
from typing import Any, Dict, Iterable, Optional, Union

import pandas as pd
import numpy as np
import pandas as pd

from countess.core.logger import Logger
from countess.core.parameters import ArrayParam, BaseParam, ColumnChoiceParam, FileArrayParam, FileParam, FileSaveParam, MultiParam, StringParam
from countess.core.parameters import (
ArrayParam,
BaseParam,
ColumnChoiceParam,
FileArrayParam,
FileParam,
FileSaveParam,
MultiParam,
StringParam,
)
from countess.utils.pandas import get_all_columns

PRERUN_ROW_LIMIT = 100000
Expand Down Expand Up @@ -167,7 +176,7 @@ def process_inputs(
class PandasSimplePlugin(PandasBasePlugin):
"""Base class for plugins which accept and return pandas DataFrames"""

input_columns : Dict[str, np.dtype] = {}
input_columns: Dict[str, np.dtype] = {}

def process_inputs(
self, inputs: Mapping[str, Iterable[pd.DataFrame]], logger: Logger, row_limit: Optional[int]
Expand Down Expand Up @@ -207,7 +216,6 @@ def dataframe_to_series(self, dataframe: pd.DataFrame, logger: Logger) -> pd.Ser
return NotImplementedError(f"{self.__class__}.dataframe_to_series()")

def process_dataframe(self, dataframe: pd.DataFrame, logger: Logger) -> pd.DataFrame:

series = self.dataframe_to_series(dataframe, logger)
df2 = self.series_to_dataframe(series)
df3 = dataframe.merge(df2, left_index=True, right_index=True)
Expand All @@ -234,7 +242,7 @@ def dataframe_to_series(self, dataframe: pd.DataFrame, logger: Logger) -> pd.Ser
if column_name in dataframe:
return dataframe[column_name].apply(self.process_value, logger=logger)
else:
null_values = [ self.process_value(None, logger) ] * len(dataframe)
null_values = [self.process_value(None, logger)] * len(dataframe)
s = pd.Series(null_values, index=dataframe.index)
return s

Expand Down
2 changes: 1 addition & 1 deletion countess/gui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def __init__(self, tk_parent: tk.Widget, plugin: BasePlugin, change_callback=Non

def change_parameter(self, parameter):
"""Called whenever a parameter gets changed"""
#if self.plugin.update():
# if self.plugin.update():
# self.update()
if self.change_callback:
self.change_callback(self)
Expand Down
13 changes: 6 additions & 7 deletions countess/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def show_config_subframe(self):
self.config_canvas.grid(row=3, column=0, sticky=tk.NSEW)
self.config_scrollbar.grid(row=3, column=1, sticky=tk.NS)

#self.node.prepare(self.logger)
# self.node.prepare(self.logger)

if self.node.plugin:
if self.node.notes:
Expand All @@ -113,8 +113,8 @@ def show_config_subframe(self):
tk.Button(self.frame, text=UNICODE_INFO, fg="blue", command=self.on_info_button_press).place(
anchor=tk.NE, relx=1, y=50
)
#self.node.prepare(self.logger)
#self.node.plugin.update()
# self.node.prepare(self.logger)
# self.node.plugin.update()
self.configurator = PluginConfigurator(self.config_canvas, self.node.plugin, self.config_change_callback)
self.config_subframe = self.configurator.frame
else:
Expand Down Expand Up @@ -148,7 +148,6 @@ def show_notes_widget(self, notes=""):
def show_preview_subframe(self):
if self.preview_subframe:
self.preview_subframe.destroy()
print(f"show_preview_subframe {self.node.result}")
try:
df = concat_dataframes(self.node.result)
self.preview_subframe = TabularDataFrame(self.frame)
Expand All @@ -158,8 +157,8 @@ def show_preview_subframe(self):
self.preview_subframe.columnconfigure(0, weight=1)
tk.Label(self.preview_subframe, text="no result").grid(sticky=tk.EW)

#if isinstance(self.node.result, pd.DataFrame):
#elif isinstance(self.node.result, str):
# if isinstance(self.node.result, pd.DataFrame):
# elif isinstance(self.node.result, str):
# self.preview_subframe = tk.Frame(self.frame)
# self.preview_subframe.rowconfigure(1, weight=1)
# n_lines = len(self.node.result.splitlines())
Expand All @@ -168,7 +167,7 @@ def show_preview_subframe(self):
# text.insert("1.0", self.node.result)
# text["state"] = "disabled"
# text.grid(sticky=tk.NSEW)
#else:
# else:

self.preview_subframe.grid(row=4, columnspan=2, sticky=tk.NSEW)

Expand Down
2 changes: 1 addition & 1 deletion countess/plugins/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# data types to each column



def maybe_number(x):
"""CSV is never clear on if something is actually a number so ... try it I guess ..."""
try:
Expand Down Expand Up @@ -133,6 +132,7 @@ def read_file_to_dataframe(self, file_params, logger, row_limit=None):
for n, col in enumerate(df.columns):
if not self.parameters["columns"][n]["name"].value:
self.parameters["columns"][n]["name"].value = str(col)
self.parameters["columns"][n]["type"].value = "string"

filename_column = self.parameters["filename_column"].value
if filename_column:
Expand Down
2 changes: 1 addition & 1 deletion countess/plugins/data_table.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional, Mapping, Iterable
from typing import Any, Iterable, Mapping, Optional

import pandas as pd

Expand Down
3 changes: 2 additions & 1 deletion countess/plugins/join.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def _join_how(left_required: bool, right_required: bool) -> str:
else:
return "right" if right_required else "outer"


class JoinPlugin(PandasBasePlugin):
"""Joins Pandas Dataframes"""

Expand Down Expand Up @@ -51,7 +52,7 @@ def join_dataframes(self, dataframe1: pd.DataFrame, dataframe2: pd.DataFrame, jo
join2 = join_params.get("right_on")
if join2 and join2 not in dataframe2.columns and dataframe2.index.name != join2:
dataframe2 = dataframe2.reset_index()

return dataframe1.merge(dataframe2, **join_params)

def process_inputs(
Expand Down
2 changes: 1 addition & 1 deletion countess/plugins/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def process_dataframe(self, dataframe: pd.DataFrame, logger: Logger) -> pd.DataF
df = super().process_dataframe(dataframe, logger)

if self.parameters["drop_unmatch"].value:
output_names = [ pp.name.value for pp in self.parameters["output"] ]
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:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ disable = [
"too-many-instance-attributes",
"too-many-locals",
"too-many-statements",
"too-few-public-methods",
"too-many-public-methods",
"unidiomatic-typecheck",
]
Expand Down

0 comments on commit d9577b6

Please sign in to comment.