Skip to content

Commit

Permalink
Fix calling plot with keyword arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-schlipf committed Oct 5, 2023
1 parent 3b3fed5 commit 17fdd32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/py4vasp/_third_party/graph/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,19 @@ def plot(*args, **kwargs):


def _parse_series(*args, **kwargs):
if series := _parse_multiple_series(*args, **kwargs):
return series
else:
return _parse_single_series(*args, **kwargs)


def _parse_multiple_series(*args, **kwargs):
try:
return [Series(*arg) for arg in args]
except TypeError:
# A TypeError is raised, if plot(x, y) is called instead of plot((x, y)).
# Because we creating the Series may raise another error, we leave the
# exception handling first to avoid reraising the TypeError.
pass
return []


def _parse_single_series(*args, **kwargs):
for_series = {key: val for key, val in kwargs.items() if key in Series._fields}
return Series(*args, **for_series)
2 changes: 2 additions & 0 deletions tests/third_party/graph/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def test_plot():
assert plot((x1, y1)) == Graph([series0])
assert plot((x1, y1), (x2, y2, "label2")) == Graph([series0, series2])
assert plot((x1, y1), xlabel="xaxis") == Graph([series0], xlabel="xaxis")
assert plot(x1, y=y1) == Graph(series0)
assert plot(x=x1, y=y1) == Graph(series0)


def test_plot_small_dataset():
Expand Down

0 comments on commit 17fdd32

Please sign in to comment.