Skip to content

Commit 4139240

Browse files
committed
clean up
1 parent e4dd123 commit 4139240

3 files changed

Lines changed: 10 additions & 49 deletions

File tree

holoviews/plotting/bokeh/element.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3260,7 +3260,7 @@ def _get_colormapper(
32603260
cmapper = self.handles.get(name)
32613261
if cmapper is not None:
32623262
try:
3263-
palette_changed = cmapper.palette != palette
3263+
palette_changed = bool(cmapper.palette != palette)
32643264
except Exception:
32653265
palette_changed = True
32663266
if palette_changed:

holoviews/tests/element/test_selection.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import holoviews as hv
1212
from holoviews.element.selection import spatial_select_columnar
13+
from holoviews.streams import Selection1D, SelectionXY
1314
from holoviews.testing import assert_data_equal, assert_dict_equal, assert_element_equal
1415

1516
from .._deps import dd, dd_skip, ds_skip, shapely_skip, spd_skip
@@ -222,8 +223,6 @@ def test_distribution_single_inverted(self):
222223

223224

224225
class TestSelectionBarsExpr:
225-
"""Tests for SelectionBarsExpr — tap/click-to-select on Bars elements."""
226-
227226
def setup_method(self):
228227
import holoviews.plotting.bokeh # noqa: F401
229228

@@ -234,16 +233,11 @@ def teardown_method(self):
234233
hv.Store.current_backend = self._backend
235234

236235
def _make_bars(self):
237-
from holoviews.element import Bars
238-
239-
return Bars(
240-
(["A", "B", "C", "D"], [10, 20, 5, 15]),
241-
kdims=["category"],
242-
vdims=["count"],
236+
return hv.Bars(
237+
(["A", "B", "C", "D"], [10, 20, 5, 15]), kdims=["category"], vdims=["count"]
243238
)
244239

245240
def test_bars_tap_single_category(self):
246-
"""Clicking the second bar (index 1 → 'B') returns isin(['B'])."""
247241
bars = self._make_bars()
248242
expr, bbox, region = bars._get_selection_expr_for_stream_value(index=[1])
249243
assert bbox is None
@@ -255,7 +249,6 @@ def test_bars_tap_single_category(self):
255249
)
256250

257251
def test_bars_tap_multiple_categories(self):
258-
"""Clicking bars at indices 0 and 2 returns isin(['A', 'C'])."""
259252
bars = self._make_bars()
260253
expr, bbox, region = bars._get_selection_expr_for_stream_value(index=[0, 2])
261254
assert bbox is None
@@ -267,21 +260,18 @@ def test_bars_tap_multiple_categories(self):
267260
)
268261

269262
def test_bars_tap_empty_index(self):
270-
"""An empty index list (clicked outside all bars) returns (None, None, None)."""
271263
bars = self._make_bars()
272264
expr, bbox, region = bars._get_selection_expr_for_stream_value(index=[])
273265
assert expr is None
274266
assert bbox is None
275267
assert region is None
276268

277269
def test_bars_tap_no_index_kwarg(self):
278-
"""No index kwarg at all falls through to the parent (no-op for no bounds)."""
279270
bars = self._make_bars()
280271
expr, _bbox, _region = bars._get_selection_expr_for_stream_value()
281272
assert expr is None
282273

283274
def test_bars_box_select_categorical(self):
284-
"""Box-select over categorical x-axis still works via Selection1DExpr."""
285275
bars = self._make_bars()
286276
expr, bbox, _region = bars._get_selection_expr_for_stream_value(
287277
bounds=(0, 0, 2, 25), x_selection=["A", "B", "C"]
@@ -293,13 +283,10 @@ def test_bars_box_select_categorical(self):
293283
)
294284

295285
def test_bars_selection_streams_include_selection1d(self):
296-
from holoviews.streams import Selection1D, SelectionXY
297-
298286
assert Selection1D in hv.Bars._selection_streams
299287
assert SelectionXY in hv.Bars._selection_streams
300288

301289
def test_barplot_default_tools_include_tap(self):
302-
import holoviews.plotting.bokeh # noqa: F401
303290
from holoviews.plotting.bokeh.chart import BarPlot
304291

305292
assert "tap" in BarPlot.param.default_tools.default

holoviews/tests/operation/test_operation.py

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -997,8 +997,9 @@ def test_decimate_same_y(self):
997997
pd.testing.assert_series_equal(data["x"], output["x"])
998998
pd.testing.assert_series_equal(data["y"], output["y"])
999999

1000+
1001+
class TestCategoricalAgg:
10001002
def test_categorical_agg_count(self):
1001-
"""Default aggregation counts rows per category."""
10021003
df = pd.DataFrame(
10031004
{
10041005
"x": [1, 2, 3, 4, 5],
@@ -1020,13 +1021,8 @@ def test_categorical_agg_count(self):
10201021
assert data["B"] == 2
10211022

10221023
def test_categorical_agg_sum(self):
1023-
"""Sum aggregation on a value dimension."""
10241024
df = pd.DataFrame(
1025-
{
1026-
"x": [1, 2, 3, 4],
1027-
"y": [10, 20, 30, 40],
1028-
"category": ["A", "B", "A", "B"],
1029-
}
1025+
{"x": [1, 2, 3, 4], "y": [10, 20, 30, 40], "category": ["A", "B", "A", "B"]}
10301026
)
10311027
points = hv.Points(df, kdims=["x", "y"], vdims=["category"])
10321028
bars = categorical_agg(
@@ -1045,13 +1041,8 @@ def test_categorical_agg_sum(self):
10451041
assert data["B"] == 60 # 20 + 40
10461042

10471043
def test_categorical_agg_mean(self):
1048-
"""Mean aggregation on a value dimension."""
10491044
df = pd.DataFrame(
1050-
{
1051-
"x": [1, 2, 3, 4],
1052-
"y": [10, 20, 30, 40],
1053-
"category": ["A", "B", "A", "B"],
1054-
}
1045+
{"x": [1, 2, 3, 4], "y": [10, 20, 30, 40], "category": ["A", "B", "A", "B"]}
10551046
)
10561047
points = hv.Points(df, kdims=["x", "y"], vdims=["category"])
10571048
bars = categorical_agg(points, dimension="category", value_dimension="y", function=np.mean)
@@ -1065,33 +1056,23 @@ def test_categorical_agg_mean(self):
10651056
assert data["B"] == 30.0 # (20 + 40) / 2
10661057

10671058
def test_categorical_agg_custom_label(self):
1068-
"""Custom label overrides auto-generated label."""
1069-
df = pd.DataFrame(
1070-
{
1071-
"x": [1, 2, 3],
1072-
"y": [10, 20, 30],
1073-
"category": ["A", "B", "A"],
1074-
}
1075-
)
1059+
df = pd.DataFrame({"x": [1, 2, 3], "y": [10, 20, 30], "category": ["A", "B", "A"]})
10761060
points = hv.Points(df, kdims=["x", "y"], vdims=["category"])
10771061
bars = categorical_agg(points, dimension="category", label="Total")
10781062

10791063
assert bars.vdims[0].name == "Total"
10801064

10811065
def test_categorical_agg_missing_dimension_error(self):
1082-
"""Raises ValueError when the specified dimension doesn't exist."""
10831066
points = hv.Points([(1, 2), (3, 4)])
10841067
with pytest.raises(ValueError, match="not found"):
10851068
categorical_agg(points, dimension="nonexistent")
10861069

10871070
def test_categorical_agg_no_dimension_error(self):
1088-
"""Raises ValueError when dimension param is not provided."""
10891071
points = hv.Points([(1, 2), (3, 4)])
10901072
with pytest.raises(ValueError, match="required"):
10911073
categorical_agg(points)
10921074

10931075
def test_categorical_agg_empty_element(self):
1094-
"""Returns an empty Bars element when the input is empty."""
10951076
df = pd.DataFrame({"x": [], "y": [], "category": []})
10961077
points = hv.Points(df, kdims=["x", "y"], vdims=["category"])
10971078
bars = categorical_agg(points, dimension="category")
@@ -1100,14 +1081,7 @@ def test_categorical_agg_empty_element(self):
11001081
assert len(bars) == 0
11011082

11021083
def test_categorical_agg_preserves_lineage(self):
1103-
"""Operation output has a pipeline that references the source element."""
1104-
df = pd.DataFrame(
1105-
{
1106-
"x": [1, 2, 3],
1107-
"y": [10, 20, 30],
1108-
"category": ["A", "B", "A"],
1109-
}
1110-
)
1084+
df = pd.DataFrame({"x": [1, 2, 3], "y": [10, 20, 30], "category": ["A", "B", "A"]})
11111085
points = hv.Points(df, kdims=["x", "y"], vdims=["category"])
11121086
bars = categorical_agg(points, dimension="category")
11131087

0 commit comments

Comments
 (0)