Skip to content

Commit 4947cc4

Browse files
authored
Raise a clear type error for unsupported Perspective objects (#8720)
1 parent 1e6d5fd commit 4947cc4

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

panel/pane/perspective.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,11 @@ def __init__(self, object=None, **params):
363363
def _get_data(self):
364364
if self.object is None:
365365
return {}, {}
366+
# ReactiveData builds the data during super().__init__, before PaneBase
367+
# gets to validate the object, so the type check has to happen here to
368+
# cover both construction and later assignment to .object.
369+
if self.applies(self.object) is False:
370+
self._type_error(self.object)
366371
if isinstance(self.object, dict):
367372
ncols = len(self.object)
368373
df = data = self.object

panel/tests/pane/test_perspective.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pytest
2+
13
from panel.pane import Perspective
24

35
data = {
@@ -10,6 +12,18 @@
1012
}
1113

1214

15+
def test_perspective_rejects_unsupported_object():
16+
with pytest.raises(ValueError, match='does not support objects of type'):
17+
Perspective('not tabular')
18+
19+
20+
def test_perspective_rejects_unsupported_object_on_assignment():
21+
psp = Perspective(data)
22+
23+
with pytest.raises(ValueError, match='does not support objects of type'):
24+
psp.object = 'not tabular'
25+
26+
1327
def test_perspective_int_cols(document, comm):
1428
psp = Perspective(
1529
data, columns=[0], aggregates={0: 'mean'}, sort=[[0, 'desc']],

0 commit comments

Comments
 (0)