Skip to content

Commit

Permalink
fix: derive format from path in Plot.plot
Browse files Browse the repository at this point in the history
  • Loading branch information
juba committed May 27, 2024
1 parent 1c6553c commit 1af4701
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/pyobsplot/js_modules.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import io
from functools import partial
from pathlib import Path
from typing import Callable, Literal

from pyobsplot.obsplot import Obsplot
Expand Down Expand Up @@ -35,7 +37,16 @@ def plot(
if provided, plot is saved to disk to an HTML file instead of displayed
as a jupyter widget, by default None
"""
format_value = format or _plot_format
format_value = format
if path is not None and not isinstance(path, io.StringIO):
extension = Path(path).suffix.lower()[1:]
allowed_extensions = ["html", "svg", "pdf", "png"]
if extension not in allowed_extensions:
msg = f"Output file extension should be one of {allowed_extensions}"
raise ValueError(msg)
format_value = format_value or extension

format_value = format_value or _plot_format
op = Obsplot(format=format_value) # type: ignore
return op(spec, path=path)

Expand Down

0 comments on commit 1af4701

Please sign in to comment.