Skip to content

Commit

Permalink
fix some syntaxes
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjinliu committed Jan 9, 2023
1 parent 9239de0 commit ba23571
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
19 changes: 7 additions & 12 deletions examples/03-0_data_changed_signal.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import sys
from tabulous import TableViewer
from tabulous.types import ItemInfo
import numpy as np

PY_38 = sys.version_info <= (3, 8)

if __name__ == "__main__":
viewer = TableViewer()
size = 100
Expand All @@ -24,15 +21,13 @@ def _on_data_change(info: ItemInfo):
f"{info.old_value} to {info.value}."
)

if PY_38:
# NOTE: Python <= 3.8 does not support __getitem__ in a decorator
def _on_data_change(info: ItemInfo):
print("data at row 0 changed.")
table.events.data[0, :].connect(_on_data_change)
def _on_data_change(info: ItemInfo):
print("data at row 0 changed.")
table.events.data[0, :].connect(_on_data_change)

else:
@table.events.data[0, :].connect
def _on_data_change(info: ItemInfo):
print("data at row 0 changed.")
# NOTE: Python >= 3.9 supports this syntax
# >>> @table.events.data[0, :].connect
# >>> def _on_data_change(info: ItemInfo):
# ... print("data at row 0 changed.")

viewer.show()
3 changes: 1 addition & 2 deletions tabulous/_colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import pandas as pd

_TimeLike = Union[pd.Timestamp, pd.Timedelta]
_ColorType = tuple[int, int, int, int]


_ColorType = tuple[int, int, int, int]
_DEFAULT_MIN = "#697FD1"
_DEFAULT_MAX = "#FF696B"

Expand Down
4 changes: 2 additions & 2 deletions tabulous/commands/_dialogs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from functools import partial
from typing import List, Union, TYPE_CHECKING
from typing import List, Union, TYPE_CHECKING, Tuple
from typing_extensions import Annotated

import logging
Expand Down Expand Up @@ -206,7 +206,7 @@ def hist(
label: SelectionOperator,
table: TableBase,
bins: int = 10,
range: tuple[str, str] = ("", ""),
range: Tuple[str, str] = ("", ""),
alpha: float = 1.0,
density: bool = False,
histtype: str = "bar",
Expand Down
5 changes: 4 additions & 1 deletion tabulous/widgets/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,10 @@ def _normalize_data(data) -> pd.DataFrame:
import pandas as pd

if not isinstance(data, pd.DataFrame):
mod = type(data).__module__.split(".", 1)[0]
try:
mod = type(data).__module__.split(".", 1)[0]
except AttributeError:
mod = ""
if mod == "polars":
import polars as pl

Expand Down
2 changes: 1 addition & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_io():
tbl.read_csv(DATA_PATH / "test.csv").close()

@pytest.mark.parametrize(
"fname", [f for f in glob("examples/*.py") if "napari" not in f]
"fname", [f for f in glob("examples/*.py") if "napari" not in f and "seaborn" not in f]
)
def test_examples(fname):
with warnings.catch_warnings():
Expand Down

0 comments on commit ba23571

Please sign in to comment.