Skip to content

Fix ValueError in get_graph_kwargs #14022

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

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/bokeh/plotting/_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,20 @@
# Dev API
#-----------------------------------------------------------------------------

def get_graph_kwargs(node_source: ColumnDataSource, edge_source: ColumnDataSource, **kwargs):
def get_graph_kwargs(node_source: ColumnDataSource, edge_source: ColumnDataSource, **kwargs) -> dict:

if not isinstance(node_source, ColumnarDataSource):
try:
# try converting the source to ColumnDataSource
node_source = ColumnDataSource(node_source)
except ValueError as err:
msg = f"Failed to auto-convert {type(node_source)} to ColumnDataSource.\n Original error: {err.message}"
msg = f"Failed to auto-convert {type(node_source)} to ColumnDataSource.\n Original error: {err}"
raise ValueError(msg).with_traceback(sys.exc_info()[2])

if not isinstance(edge_source, ColumnarDataSource):
try:
# try converting the source to ColumnDataSource
edge_source = ColumnDataSource(edge_source)
except ValueError as err:
msg = f"Failed to auto-convert {type(edge_source)} to ColumnDataSource.\n Original error: {err.message}"
msg = f"Failed to auto-convert {type(edge_source)} to ColumnDataSource.\n Original error: {err}"
raise ValueError(msg).with_traceback(sys.exc_info()[2])

marker = kwargs.pop('node_marker', None)
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/bokeh/plotting/test__graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ def test_default_muted_glyph(self) -> None:
assert r.muted_glyph.line_alpha == 0.2
assert r.muted_glyph.line_color == "blue"

def test_bad_input(self) -> None:
msg = "Failed to auto-convert <class 'int'> to ColumnDataSource.\n Original error: expected a dict or pandas.DataFrame, got 42"
with pytest.raises(ValueError, match=msg):
bpg.get_graph_kwargs(42, {})

with pytest.raises(ValueError, match=msg):
bpg.get_graph_kwargs({}, 42)

#-----------------------------------------------------------------------------
# Private API
#-----------------------------------------------------------------------------
Loading