Skip to content

Commit e259826

Browse files
committed
Add tests for geom_aggregate
1 parent d76d01e commit e259826

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

holoviews/tests/operation/test_datashader.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,92 @@ def test_selector_single_categorical():
15371537
renderer("bokeh").get_plot(plot)
15381538

15391539

1540+
def test_geom_aggregate_with_summary():
1541+
rects = Rectangles([
1542+
(0, 0, 1, 1, 128, 100, 200),
1543+
(2, 3, 4, 6, 100, 50, 80),
1544+
(0.5, 2, 1.5, 4, 20, 200, 120),
1545+
(2, 1, 3.5, 2.5, 110, 40, 240),
1546+
], vdims=["r", "g", "b"])
1547+
agg = rasterize(
1548+
rects,
1549+
width=4,
1550+
height=4,
1551+
dynamic=False,
1552+
aggregator=ds.summary(
1553+
r=ds.where(ds.max("x0"), "r"),
1554+
g=ds.where(ds.max("x0"), "g"),
1555+
b=ds.where(ds.max("x0"), "b"),
1556+
)
1557+
)
1558+
1559+
assert isinstance(agg, Image)
1560+
assert isinstance(agg.data, xr.Dataset)
1561+
assert "r" in agg.data
1562+
assert "g" in agg.data
1563+
assert "b" in agg.data
1564+
1565+
1566+
def test_geom_aggregate_with_selector():
1567+
rects = Rectangles([
1568+
(0, 0, 1, 1, 10, 0),
1569+
(2, 3, 4, 6, 20, 1),
1570+
(0.5, 2, 1.5, 4, 30, 2),
1571+
(2, 1, 3.5, 2.5, 40, 3),
1572+
], vdims=["value", "index_col"])
1573+
agg = rasterize(
1574+
rects,
1575+
width=4,
1576+
height=4,
1577+
dynamic=False,
1578+
selector=ds.first("value")
1579+
)
1580+
1581+
assert isinstance(agg, Image)
1582+
assert isinstance(agg.data, xr.Dataset)
1583+
expected_columns = ['__index__', 'x0', 'y0', 'x1', 'y1', 'value', 'index_col']
1584+
assert agg.data.attrs["selector_columns"] == expected_columns
1585+
for c in expected_columns:
1586+
assert c in agg.data
1587+
1588+
agg_where = rasterize(
1589+
rects,
1590+
width=4,
1591+
height=4,
1592+
dynamic=False,
1593+
aggregator=ds.where(ds.first("value"), "index_col")
1594+
)
1595+
np.testing.assert_array_equal(
1596+
agg.data["__index__"],
1597+
agg_where.data["index_col"].fillna(-1)
1598+
)
1599+
1600+
1601+
def test_geom_aggregate_with_by_and_selector():
1602+
rects = Rectangles([
1603+
(0, 0, 1, 2, 'A', 20, 0),
1604+
(1, 1, 3, 2, 'B', 300, 1),
1605+
], vdims=['cat', "value", "index_col"])
1606+
agg = rasterize(
1607+
rects,
1608+
width=4,
1609+
height=4,
1610+
dynamic=False,
1611+
aggregator=ds.count_cat('cat'),
1612+
selector=ds.first("value")
1613+
)
1614+
1615+
assert isinstance(agg, ImageStack)
1616+
assert "A" in agg.vdims
1617+
assert "B" in agg.vdims
1618+
1619+
assert isinstance(agg.data, xr.Dataset)
1620+
expected_columns = ['__index__', 'x0', 'y0', 'x1', 'y1', 'cat', 'value', 'index_col']
1621+
assert agg.data.attrs["selector_columns"] == expected_columns
1622+
for c in expected_columns:
1623+
assert c in agg.data
1624+
1625+
15401626
class DatashaderSpreadTests(ComparisonTestCase):
15411627

15421628
def test_spread_rgb_1px(self):

0 commit comments

Comments
 (0)