Skip to content

Commit e54b351

Browse files
committed
code tidy
1 parent a71156f commit e54b351

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

countess/gui/tabular.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class TabularDataFrame(tk.Frame):
103103
columns: list[tk.Text] = []
104104
column_formats: list[str] = []
105105
scrollbar = None
106-
sort_by_col = None
106+
sort_by_col: Optional[int] = None
107107
sort_ascending = True
108108
callback: Optional[Callable[[int, int, bool], None]] = None
109109
click_callback: Optional[Callable[[int, int, int], None]] = None
@@ -198,6 +198,8 @@ def _column_click(self, col: int, ev):
198198

199199
def refresh(self, new_offset: float = 0):
200200
# Refreshes the column widgets.
201+
assert self.table
202+
assert self.scrollbar
201203

202204
self.offset = max(0, min(self.length - self.height, int(new_offset)))
203205

countess/plugins/csv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import gzip
44
import logging
55
from io import BufferedWriter, BytesIO
6-
from typing import Any, List, Optional, Sequence, Tuple, Union
6+
from typing import List, Optional, Sequence, Tuple, Union
77

88
import duckdb
99
from duckdb import DuckDBPyConnection, DuckDBPyRelation
@@ -20,7 +20,7 @@
2020
StringParam,
2121
)
2222
from countess.core.plugins import DuckdbLoadFilePlugin, DuckdbSaveFilePlugin
23-
from countess.utils.duckdb import duckdb_escape_identifier, duckdb_escape_literal, duckdb_source_to_view
23+
from countess.utils.duckdb import duckdb_escape_identifier, duckdb_escape_literal
2424
from countess.utils.files import clean_filename
2525

2626
CSV_FILE_TYPES: Sequence[Tuple[str, Union[str, List[str]]]] = [

countess/plugins/pivot.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import functools
21
import logging
32
from typing import Optional
43

@@ -7,12 +6,7 @@
76
from countess import VERSION
87
from countess.core.parameters import BooleanParam, ChoiceParam, PerColumnArrayParam
98
from countess.core.plugins import DuckdbSimplePlugin
10-
from countess.utils.duckdb import (
11-
duckdb_choose_special,
12-
duckdb_escape_identifier,
13-
duckdb_escape_literal,
14-
duckdb_source_to_view,
15-
)
9+
from countess.utils.duckdb import duckdb_choose_special, duckdb_escape_identifier, duckdb_escape_literal
1610

1711
logger = logging.getLogger(__name__)
1812

countess/plugins/score.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from math import log
2-
from typing import Any, List, Optional, Union
2+
from typing import Any, Optional, Union
33

44
import numpy as np
5-
import pandas as pd
65
from scipy.optimize import curve_fit
76

87
from countess import VERSION
@@ -64,7 +63,7 @@ def output_columns(self) -> dict[str, str]:
6463

6564
def prepare(self, source):
6665
yaxis_prefix = self.columns.get_column_prefix()
67-
suffix_set = set([k.removeprefix(yaxis_prefix) for k in source.columns if k.startswith(yaxis_prefix)])
66+
suffix_set = {k.removeprefix(yaxis_prefix) for k in source.columns if k.startswith(yaxis_prefix)}
6867

6968
if self.xaxis.is_not_none():
7069
xaxis_prefix = self.xaxis.get_column_prefix()
@@ -73,6 +72,8 @@ def prepare(self, source):
7372
self.suffixes = sorted(suffix_set)
7473

7574
def transform(self, data: dict[str, Any]) -> Optional[dict[str, Any]]:
75+
assert self.suffixes
76+
7677
if self.xaxis.is_not_none():
7778
xaxis_prefix = self.xaxis.get_column_prefix()
7879
x_values = [data.get(xaxis_prefix + s) for s in self.suffixes]
@@ -85,17 +86,22 @@ def transform(self, data: dict[str, Any]) -> Optional[dict[str, Any]]:
8586
return None
8687

8788
if self.log:
88-
y_values = [log(y + 1) for y in y_values]
89+
y_values = [log(y + 1) if y is not None else None for y in y_values]
8990
if self.normalize:
90-
max_y = max(y_values)
91-
y_values = [y / max_y for y in y_values]
91+
max_y = max(y for y in y_values if y is not None)
92+
y_values = [y / max_y if y is not None else None for y in y_values]
9293

93-
x_values, y_values = zip(*[(x, y) for x, y in zip(x_values, y_values) if x > 0 or y > 0])
94+
x_values, y_values = zip(
95+
*[(x, y) for x, y in zip(x_values, y_values) if x is not None and y is not None and (x > 0 or y > 0)]
96+
)
9497
if len(x_values) < len(self.suffixes) / 2 + 1:
9598
return None
9699

97-
s, v = score(x_values, y_values)
98-
if self.variance:
99-
return {self.output.value: s, self.variance.value: v}
100-
else:
101-
return {self.output.value: s}
100+
try:
101+
s, v = score(x_values, y_values)
102+
if self.variance:
103+
return {self.output.value: s, self.variance.value: v}
104+
else:
105+
return {self.output.value: s}
106+
except TypeError:
107+
return None

0 commit comments

Comments
 (0)