Skip to content

Commit 2b9d6fc

Browse files
committed
style: Run ruff
1 parent 3f629f7 commit 2b9d6fc

7 files changed

Lines changed: 124 additions & 117 deletions

File tree

altair_upset/preprocessing.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,27 @@ def preprocess_data(data, sets, abbre, sort_order):
55
"""Handles the data preprocessing for UpSet plots."""
66
# Create a copy to avoid SettingWithCopyWarning
77
data = data.copy()
8-
8+
99
# Handle empty input data
1010
if len(data) == 0:
1111
# Create empty result DataFrame with required columns
1212
data = pd.DataFrame(columns=sets + ["count", "intersection_id", "degree"])
1313
data = pd.melt(data, id_vars=["intersection_id", "count", "degree"])
1414
data = data.rename(columns={"variable": "set", "value": "is_intersect"})
15-
15+
1616
if abbre is None:
1717
abbre = sets
18-
18+
1919
set_to_abbre = pd.DataFrame(
20-
[[sets[i], abbre[i]] for i in range(len(sets))], columns=["set", "set_abbre"]
20+
[[sets[i], abbre[i]] for i in range(len(sets))],
21+
columns=["set", "set_abbre"],
2122
)
2223
set_to_order = pd.DataFrame(
2324
[[sets[i], 1 + sets.index(sets[i])] for i in range(len(sets))],
2425
columns=["set", "set_order"],
2526
)
2627
return data, set_to_abbre, set_to_order, abbre
27-
28+
2829
# Process non-empty data
2930
data.loc[:, "count"] = 0
3031
data = data[sets + ["count"]]

altair_upset/upset.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ def UpSetAltair(
209209
if horizontal_bar_chart_width is None:
210210
horizontal_bar_chart_width = int(width * 0.15) # Make it 25% of total width
211211
vertical_bar_chart_height = height * height_ratio
212-
matrix_height = (height - vertical_bar_chart_height) * 0.8 # Reduce height to tighten spacing
212+
matrix_height = (
213+
height - vertical_bar_chart_height
214+
) * 0.8 # Reduce height to tighten spacing
213215
matrix_width = width - horizontal_bar_chart_width
214216

215217
# Automatic padding

docs/conf.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
sys.path.insert(0, str(Path(__file__).parent.parent.resolve()))
1010

1111
# Project information
12-
project = 'altair-upset'
13-
copyright = f'2024-{datetime.now().year}, Edmund Miller'
14-
author = 'Edmund Miller'
12+
project = "altair-upset"
13+
copyright = f"2024-{datetime.now().year}, Edmund Miller"
14+
author = "Edmund Miller"
1515

1616
# Extensions
1717
extensions = [
@@ -48,28 +48,28 @@
4848

4949
# Intersphinx mapping
5050
intersphinx_mapping = {
51-
'python': ('https://docs.python.org/3', None),
52-
'altair': ('https://altair-viz.github.io/', None),
53-
'pandas': ('https://pandas.pydata.org/docs/', None),
51+
"python": ("https://docs.python.org/3", None),
52+
"altair": ("https://altair-viz.github.io/", None),
53+
"pandas": ("https://pandas.pydata.org/docs/", None),
5454
}
5555

5656
# Paths and static files
57-
html_static_path = ['_static'] # Include _static directory
57+
html_static_path = ["_static"] # Include _static directory
5858
html_css_files = [
59-
'custom.css',
59+
"custom.css",
6060
]
61-
templates_path = ['_templates']
62-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
61+
templates_path = ["_templates"]
62+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
6363

6464
# Numpydoc settings
6565
numpydoc_show_class_members = False
6666
numpydoc_show_inherited_class_members = False
6767
numpydoc_class_members_toctree = False
6868

6969
# Autodoc settings
70-
autodoc_default_flags = ['members', 'inherited-members']
71-
autodoc_member_order = 'groupwise'
72-
autodoc_typehints = 'none'
70+
autodoc_default_flags = ["members", "inherited-members"]
71+
autodoc_member_order = "groupwise"
72+
autodoc_typehints = "none"
7373

7474
# Generate autosummary even if no references
7575
autosummary_generate = True

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ addopts = "--cov=altair_upset --cov-report=term-missing"
6363
[tool.ruff]
6464
line-length = 88
6565
target-version = "py38"
66-
select = ["E", "F", "I", "UP"]
66+
lint.select = ["E", "F", "I", "UP"]
6767

6868
[tool.mypy]
6969
python_version = "3.8"

tests/test_advanced_features.py

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,140 +12,137 @@ def sample_data():
1212
"""Create sample dataset for testing."""
1313
np.random.seed(42)
1414
n_samples = 100
15-
15+
1616
# Create set membership data
17-
data = pd.DataFrame({
18-
'A': np.random.choice([0, 1], size=n_samples, p=[0.3, 0.7]),
19-
'B': np.random.choice([0, 1], size=n_samples, p=[0.4, 0.6]),
20-
'C': np.random.choice([0, 1], size=n_samples, p=[0.5, 0.5])
21-
})
22-
17+
data = pd.DataFrame(
18+
{
19+
"A": np.random.choice([0, 1], size=n_samples, p=[0.3, 0.7]),
20+
"B": np.random.choice([0, 1], size=n_samples, p=[0.4, 0.6]),
21+
"C": np.random.choice([0, 1], size=n_samples, p=[0.5, 0.5]),
22+
}
23+
)
24+
2325
# Add set-specific attributes
24-
data['set_size'] = data.sum(axis=1) # Number of sets each element belongs to
25-
26+
data["set_size"] = data.sum(axis=1) # Number of sets each element belongs to
27+
2628
return data
2729

2830

2931
@pytest.fixture
3032
def basic_chart(sample_data):
3133
"""Create basic UpSet chart for testing."""
32-
return au.UpSetAltair(
33-
data=sample_data,
34-
sets=['A', 'B', 'C'],
35-
title="Test Chart"
36-
)
34+
return au.UpSetAltair(data=sample_data, sets=["A", "B", "C"], title="Test Chart")
3735

3836

3937
def test_basic_chart_structure(basic_chart):
4038
"""Test that the basic chart has all required components."""
4139
# The chart should be a VConcatChart (vertical concatenation)
4240
assert isinstance(basic_chart.chart, alt.VConcatChart)
43-
41+
4442
# Should have intersection matrix and bar charts
4543
assert len(basic_chart.chart.vconcat) == 2 # Vertical components
46-
assert isinstance(basic_chart.chart.vconcat[1], alt.HConcatChart) # Horizontal components
44+
assert isinstance(
45+
basic_chart.chart.vconcat[1], alt.HConcatChart
46+
) # Horizontal components
4747

4848

4949
def test_set_size_encoding(basic_chart):
5050
"""Test that set sizes are correctly encoded."""
5151
# Get the horizontal bar chart component
5252
hconcat = basic_chart.chart.vconcat[1]
5353
horizontal_bar = hconcat.hconcat[-1]
54-
54+
5555
# Check encoding - need to convert to dict to access field values
5656
encoding_dict = horizontal_bar.encoding.to_dict()
57-
assert encoding_dict['x']['field'] == 'count'
58-
assert encoding_dict['y']['field'] == 'set_order'
57+
assert encoding_dict["x"]["field"] == "count"
58+
assert encoding_dict["y"]["field"] == "set_order"
5959

6060

6161
def test_intersection_encoding(basic_chart):
6262
"""Test that intersections are correctly encoded."""
6363
# Get the matrix view component
6464
hconcat = basic_chart.chart.vconcat[1]
6565
matrix = hconcat.hconcat[0]
66-
66+
6767
# Convert encodings to dict for checking
68-
encoding_dict = matrix.layer[0].encoding.to_dict() # Use first layer for matrix encodings
69-
assert encoding_dict['x']['field'] == 'intersection_id'
70-
assert encoding_dict['y']['field'] == 'set_order'
68+
encoding_dict = matrix.layer[
69+
0
70+
].encoding.to_dict() # Use first layer for matrix encodings
71+
assert encoding_dict["x"]["field"] == "intersection_id"
72+
assert encoding_dict["y"]["field"] == "set_order"
7173

7274

7375
def test_interactive_legend(basic_chart):
7476
"""Test that the chart has interactive legend selection."""
7577
# Check for legend selection parameter
7678
params = basic_chart.chart.params
77-
assert any('legend' in str(p) for p in params)
79+
assert any("legend" in str(p) for p in params)
7880

7981

8082
def test_hover_interaction(basic_chart):
8183
"""Test that the chart has hover interactions."""
8284
# Get the matrix view component
8385
hconcat = basic_chart.chart.vconcat[1]
8486
matrix = hconcat.hconcat[0]
85-
87+
8688
# Check for tooltips in any layer of the matrix
8789
has_tooltip = False
8890
for layer in matrix.layer:
89-
if hasattr(layer, 'encoding'):
91+
if hasattr(layer, "encoding"):
9092
encoding_dict = layer.encoding.to_dict()
91-
if 'tooltip' in encoding_dict:
93+
if "tooltip" in encoding_dict:
9294
has_tooltip = True
9395
break
94-
96+
9597
assert has_tooltip, "No tooltip found in matrix view"
9698

9799

98100
def test_sort_by_frequency(sample_data):
99101
"""Test sorting intersections by frequency."""
100102
chart = au.UpSetAltair(
101103
data=sample_data,
102-
sets=['A', 'B', 'C'],
103-
sort_by='frequency',
104-
sort_order='descending'
104+
sets=["A", "B", "C"],
105+
sort_by="frequency",
106+
sort_order="descending",
105107
)
106-
108+
107109
# Get the matrix view component
108110
matrix_view = chart.chart.vconcat[1].hconcat[0]
109-
111+
110112
# Check sort configuration in the first layer
111113
encoding_dict = matrix_view.layer[0].encoding.to_dict()
112-
sort_config = encoding_dict['x'].get('sort', {})
113-
114-
assert sort_config.get('field') == 'count'
115-
assert sort_config.get('order') == 'descending'
114+
sort_config = encoding_dict["x"].get("sort", {})
115+
116+
assert sort_config.get("field") == "count"
117+
assert sort_config.get("order") == "descending"
116118

117119

118120
def test_sort_by_degree(sample_data):
119121
"""Test sorting intersections by degree."""
120122
chart = au.UpSetAltair(
121-
data=sample_data,
122-
sets=['A', 'B', 'C'],
123-
sort_by='degree',
124-
sort_order='ascending'
123+
data=sample_data, sets=["A", "B", "C"], sort_by="degree", sort_order="ascending"
125124
)
126-
125+
127126
# Get the matrix view component
128127
matrix_view = chart.chart.vconcat[1].hconcat[0]
129-
128+
130129
# Check sort configuration in the first layer
131130
encoding_dict = matrix_view.layer[0].encoding.to_dict()
132-
sort_config = encoding_dict['x'].get('sort', {})
133-
134-
assert sort_config.get('field') == 'degree'
135-
assert sort_config.get('order') == 'ascending'
131+
sort_config = encoding_dict["x"].get("sort", {})
132+
133+
assert sort_config.get("field") == "degree"
134+
assert sort_config.get("order") == "ascending"
136135

137136

138137
def test_custom_colors(sample_data):
139138
"""Test applying custom colors to the chart."""
140139
custom_colors = ["#FF0000", "#00FF00", "#0000FF"]
141140
chart = au.UpSetAltair(
142-
data=sample_data,
143-
sets=['A', 'B', 'C'],
144-
color_range=custom_colors
141+
data=sample_data, sets=["A", "B", "C"], color_range=custom_colors
145142
)
146-
143+
147144
# Check that custom colors are applied
148145
hconcat = chart.chart.vconcat[1]
149146
horizontal_bar = hconcat.hconcat[-1]
150-
assert 'scale' in str(horizontal_bar.encoding.color)
147+
assert "scale" in str(horizontal_bar.encoding.color)
151148
assert all(color in str(horizontal_bar.encoding.color) for color in custom_colors)

0 commit comments

Comments
 (0)