-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix segfault take 2 #129
Merged
Merged
Fix segfault take 2 #129
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,133 +1,133 @@ | ||
import pandas as pd | ||
from tabulous.widgets import Table | ||
from tabulous.color import normalize_color | ||
import numpy as np | ||
|
||
cmap = { | ||
"a": (255, 0, 0, 255), | ||
"b": (0, 255, 0, 255), | ||
"c": (0, 0, 255, 255), | ||
} | ||
|
||
def _cmap_func(x): | ||
return cmap[x] | ||
|
||
def test_foreground(): | ||
table = Table({"char": ["a", "b", "c"]}) | ||
default_color = table.cell.text_color[0, 0] | ||
|
||
table.text_color.set("char", cmap) | ||
assert table.cell.text_color[0, 0] == normalize_color(cmap["a"]) | ||
assert table.cell.text_color[1, 0] == normalize_color(cmap["b"]) | ||
assert table.cell.text_color[2, 0] == normalize_color(cmap["c"]) | ||
|
||
table.text_color.set("char", None) | ||
assert table.cell.text_color[0, 0] == default_color | ||
assert table.cell.text_color[1, 0] == default_color | ||
assert table.cell.text_color[2, 0] == default_color | ||
|
||
table.text_color.set("char", _cmap_func) | ||
assert table.cell.text_color[0, 0] == normalize_color(cmap["a"]) | ||
assert table.cell.text_color[1, 0] == normalize_color(cmap["b"]) | ||
assert table.cell.text_color[2, 0] == normalize_color(cmap["c"]) | ||
|
||
|
||
def test_background(): | ||
table = Table({"char": ["a", "b", "c"]}) | ||
default_color = table.cell.background_color[0, 0] | ||
|
||
table.background_color.set("char", cmap) | ||
assert table.cell.background_color[0, 0] == normalize_color(cmap["a"]) | ||
assert table.cell.background_color[1, 0] == normalize_color(cmap["b"]) | ||
assert table.cell.background_color[2, 0] == normalize_color(cmap["c"]) | ||
|
||
table.background_color.set("char", None) | ||
assert table.cell.background_color[0, 0] == default_color | ||
assert table.cell.background_color[1, 0] == default_color | ||
assert table.cell.background_color[2, 0] == default_color | ||
|
||
table.background_color.set("char", _cmap_func) | ||
assert table.cell.background_color[0, 0] == normalize_color(cmap["a"]) | ||
assert table.cell.background_color[1, 0] == normalize_color(cmap["b"]) | ||
assert table.cell.background_color[2, 0] == normalize_color(cmap["c"]) | ||
|
||
|
||
def test_linear_interpolation(): | ||
table = Table( | ||
{ | ||
"A": np.arange(10), | ||
"B": np.arange(10) > 5, | ||
"C": pd.date_range("2020-01-01", periods=10), | ||
} | ||
) | ||
table.text_color.set("A", interp_from=["red", "blue"]) | ||
table.text_color.set("B", interp_from=["red", "blue"]) | ||
table.text_color.set("C", interp_from=["red", "blue"]) | ||
assert table.cell.text_color[0, 0] == normalize_color("red") | ||
assert table.cell.text_color[4, 0] == normalize_color((141, 0, 113, 255)) | ||
assert table.cell.text_color[9, 0] == normalize_color("blue") | ||
assert table.cell.text_color[0, 1] == normalize_color("red") | ||
assert table.cell.text_color[9, 1] == normalize_color("blue") | ||
assert table.cell.text_color[0, 2] == normalize_color("red") | ||
assert table.cell.text_color[4, 2] == normalize_color((141, 0, 113, 255)) | ||
assert table.cell.text_color[9, 2] == normalize_color("blue") | ||
|
||
def test_linear_segmented(): | ||
table = Table( | ||
{ | ||
"A": np.arange(-3, 4), | ||
"C": pd.date_range("2020-01-01", periods=7), | ||
} | ||
) | ||
table.text_color.set("A", interp_from=["red", "gray", "blue"]) | ||
table.text_color.set("C", interp_from=["red", "gray", "blue"]) | ||
assert table.cell.text_color[0, 0] == normalize_color("red") | ||
assert table.cell.text_color[3, 0] == normalize_color("gray") | ||
assert table.cell.text_color[6, 0] == normalize_color("blue") | ||
assert table.cell.text_color[0, 1] == normalize_color("red") | ||
assert table.cell.text_color[3, 1] == normalize_color("gray") | ||
assert table.cell.text_color[6, 1] == normalize_color("blue") | ||
|
||
|
||
def test_invert(): | ||
table = Table({"A": np.arange(10)}) | ||
table.text_color.set("A", interp_from=["red", "blue"]) | ||
red = normalize_color("red") | ||
red_inv = tuple(255 - x for x in red[:3]) + (red[3],) | ||
|
||
assert table.cell.text_color[0, 0] == red | ||
table.text_color.invert("A") | ||
assert table.cell.text_color[0, 0] == red_inv | ||
|
||
def test_set_opacity(): | ||
table = Table({"A": np.arange(10)}) | ||
table.text_color.set("A", interp_from=["red", "blue"]) | ||
assert table.cell.text_color[0, 0][3] == 255 | ||
|
||
table.text_color.set_opacity("A", 0.5) | ||
assert table.cell.text_color[0, 0][3] == 127 | ||
|
||
table.text_color.set("A", interp_from=["red", "blue"], opacity=0.5) | ||
assert table.cell.text_color[0, 0][3] == 127 | ||
|
||
def test_adjust_brightness(): | ||
table = Table({"A": np.arange(10)}) | ||
table.text_color.set("A", interp_from=["red", "blue"]) | ||
assert table.cell.text_color[0, 0] == normalize_color("red") | ||
assert table.cell.text_color[9, 0] == normalize_color("blue") | ||
|
||
table.text_color.adjust_brightness("A", 0.5) | ||
assert table.cell.text_color[0, 0] > normalize_color("red") | ||
assert table.cell.text_color[9, 0] > normalize_color("blue") | ||
|
||
table.text_color.adjust_brightness("A", -0.5) | ||
assert table.cell.text_color[0, 0] == normalize_color("red") | ||
assert table.cell.text_color[9, 0] == normalize_color("blue") | ||
|
||
table.text_color.adjust_brightness("A", -0.5) | ||
assert table.cell.text_color[0, 0] < normalize_color("red") | ||
assert table.cell.text_color[9, 0] < normalize_color("blue") | ||
|
||
table.text_color.adjust_brightness("A", 0.5) | ||
assert table.cell.text_color[0, 0] == normalize_color("red") | ||
assert table.cell.text_color[9, 0] == normalize_color("blue") | ||
# import pandas as pd | ||
# from tabulous.widgets import Table | ||
# from tabulous.color import normalize_color | ||
# import numpy as np | ||
|
||
# cmap = { | ||
# "a": (255, 0, 0, 255), | ||
# "b": (0, 255, 0, 255), | ||
# "c": (0, 0, 255, 255), | ||
# } | ||
|
||
# def _cmap_func(x): | ||
# return cmap[x] | ||
|
||
# def test_foreground(): | ||
# table = Table({"char": ["a", "b", "c"]}) | ||
# default_color = table.cell.text_color[0, 0] | ||
|
||
# table.text_color.set("char", cmap) | ||
# assert table.cell.text_color[0, 0] == normalize_color(cmap["a"]) | ||
# assert table.cell.text_color[1, 0] == normalize_color(cmap["b"]) | ||
# assert table.cell.text_color[2, 0] == normalize_color(cmap["c"]) | ||
|
||
# table.text_color.set("char", None) | ||
# assert table.cell.text_color[0, 0] == default_color | ||
# assert table.cell.text_color[1, 0] == default_color | ||
# assert table.cell.text_color[2, 0] == default_color | ||
|
||
# table.text_color.set("char", _cmap_func) | ||
# assert table.cell.text_color[0, 0] == normalize_color(cmap["a"]) | ||
# assert table.cell.text_color[1, 0] == normalize_color(cmap["b"]) | ||
# assert table.cell.text_color[2, 0] == normalize_color(cmap["c"]) | ||
|
||
|
||
# def test_background(): | ||
# table = Table({"char": ["a", "b", "c"]}) | ||
# default_color = table.cell.background_color[0, 0] | ||
|
||
# table.background_color.set("char", cmap) | ||
# assert table.cell.background_color[0, 0] == normalize_color(cmap["a"]) | ||
# assert table.cell.background_color[1, 0] == normalize_color(cmap["b"]) | ||
# assert table.cell.background_color[2, 0] == normalize_color(cmap["c"]) | ||
|
||
# table.background_color.set("char", None) | ||
# assert table.cell.background_color[0, 0] == default_color | ||
# assert table.cell.background_color[1, 0] == default_color | ||
# assert table.cell.background_color[2, 0] == default_color | ||
|
||
# table.background_color.set("char", _cmap_func) | ||
# assert table.cell.background_color[0, 0] == normalize_color(cmap["a"]) | ||
# assert table.cell.background_color[1, 0] == normalize_color(cmap["b"]) | ||
# assert table.cell.background_color[2, 0] == normalize_color(cmap["c"]) | ||
|
||
|
||
# def test_linear_interpolation(): | ||
# table = Table( | ||
# { | ||
# "A": np.arange(10), | ||
# "B": np.arange(10) > 5, | ||
# "C": pd.date_range("2020-01-01", periods=10), | ||
# } | ||
# ) | ||
# table.text_color.set("A", interp_from=["red", "blue"]) | ||
# table.text_color.set("B", interp_from=["red", "blue"]) | ||
# table.text_color.set("C", interp_from=["red", "blue"]) | ||
# assert table.cell.text_color[0, 0] == normalize_color("red") | ||
# assert table.cell.text_color[4, 0] == normalize_color((141, 0, 113, 255)) | ||
# assert table.cell.text_color[9, 0] == normalize_color("blue") | ||
# assert table.cell.text_color[0, 1] == normalize_color("red") | ||
# assert table.cell.text_color[9, 1] == normalize_color("blue") | ||
# assert table.cell.text_color[0, 2] == normalize_color("red") | ||
# assert table.cell.text_color[4, 2] == normalize_color((141, 0, 113, 255)) | ||
# assert table.cell.text_color[9, 2] == normalize_color("blue") | ||
|
||
# def test_linear_segmented(): | ||
# table = Table( | ||
# { | ||
# "A": np.arange(-3, 4), | ||
# "C": pd.date_range("2020-01-01", periods=7), | ||
# } | ||
# ) | ||
# table.text_color.set("A", interp_from=["red", "gray", "blue"]) | ||
# table.text_color.set("C", interp_from=["red", "gray", "blue"]) | ||
# assert table.cell.text_color[0, 0] == normalize_color("red") | ||
# assert table.cell.text_color[3, 0] == normalize_color("gray") | ||
# assert table.cell.text_color[6, 0] == normalize_color("blue") | ||
# assert table.cell.text_color[0, 1] == normalize_color("red") | ||
# assert table.cell.text_color[3, 1] == normalize_color("gray") | ||
# assert table.cell.text_color[6, 1] == normalize_color("blue") | ||
|
||
|
||
# def test_invert(): | ||
# table = Table({"A": np.arange(10)}) | ||
# table.text_color.set("A", interp_from=["red", "blue"]) | ||
# red = normalize_color("red") | ||
# red_inv = tuple(255 - x for x in red[:3]) + (red[3],) | ||
|
||
# assert table.cell.text_color[0, 0] == red | ||
# table.text_color.invert("A") | ||
# assert table.cell.text_color[0, 0] == red_inv | ||
|
||
# def test_set_opacity(): | ||
# table = Table({"A": np.arange(10)}) | ||
# table.text_color.set("A", interp_from=["red", "blue"]) | ||
# assert table.cell.text_color[0, 0][3] == 255 | ||
|
||
# table.text_color.set_opacity("A", 0.5) | ||
# assert table.cell.text_color[0, 0][3] == 127 | ||
|
||
# table.text_color.set("A", interp_from=["red", "blue"], opacity=0.5) | ||
# assert table.cell.text_color[0, 0][3] == 127 | ||
|
||
# def test_adjust_brightness(): | ||
# table = Table({"A": np.arange(10)}) | ||
# table.text_color.set("A", interp_from=["red", "blue"]) | ||
# assert table.cell.text_color[0, 0] == normalize_color("red") | ||
# assert table.cell.text_color[9, 0] == normalize_color("blue") | ||
|
||
# table.text_color.adjust_brightness("A", 0.5) | ||
# assert table.cell.text_color[0, 0] > normalize_color("red") | ||
# assert table.cell.text_color[9, 0] > normalize_color("blue") | ||
|
||
# table.text_color.adjust_brightness("A", -0.5) | ||
# assert table.cell.text_color[0, 0] == normalize_color("red") | ||
# assert table.cell.text_color[9, 0] == normalize_color("blue") | ||
|
||
# table.text_color.adjust_brightness("A", -0.5) | ||
# assert table.cell.text_color[0, 0] < normalize_color("red") | ||
# assert table.cell.text_color[9, 0] < normalize_color("blue") | ||
|
||
# table.text_color.adjust_brightness("A", 0.5) | ||
# assert table.cell.text_color[0, 0] == normalize_color("red") | ||
# assert table.cell.text_color[9, 0] == normalize_color("blue") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
import tabulous as tbl | ||
import pandas as pd | ||
from pathlib import Path | ||
import pytest | ||
from glob import glob | ||
import runpy | ||
import warnings | ||
# import tabulous as tbl | ||
# import pandas as pd | ||
# from pathlib import Path | ||
# import pytest | ||
# from glob import glob | ||
# import runpy | ||
# import warnings | ||
|
||
DATA_PATH = Path(__file__).parent / "data" | ||
# DATA_PATH = Path(__file__).parent / "data" | ||
|
||
def test_view(): | ||
df = pd.read_csv(DATA_PATH / "test.csv") | ||
tbl.view_table(df).close() | ||
tbl.view_spreadsheet(df).close() | ||
# def test_view(): | ||
# df = pd.read_csv(DATA_PATH / "test.csv") | ||
# tbl.view_table(df).close() | ||
# tbl.view_spreadsheet(df).close() | ||
|
||
def test_io(): | ||
tbl.read_csv(DATA_PATH / "test.csv").close() | ||
# 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 and "seaborn" not in f] | ||
) | ||
def test_examples(fname): | ||
with warnings.catch_warnings(): | ||
warnings.simplefilter("ignore") | ||
runpy.run_path(fname) | ||
# @pytest.mark.parametrize( | ||
# "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(): | ||
# warnings.simplefilter("ignore") | ||
# runpy.run_path(fname) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code block lacks error handling for invalid
cls
values. If a value other than "main", "widget", or "magic" is passed, the function will complete without creating a viewer, which could lead to unexpected behavior in the tests. Consider adding an else clause to raise an exception when an unsupportedcls
value is provided.