From 17fdd32b664919c53bdc92368d29eae58aeab3c8 Mon Sep 17 00:00:00 2001 From: Martin Schlipf Date: Thu, 5 Oct 2023 12:04:49 +0200 Subject: [PATCH] Fix calling plot with keyword arguments --- src/py4vasp/_third_party/graph/plot.py | 15 +++++++++++---- tests/third_party/graph/test_plot.py | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/py4vasp/_third_party/graph/plot.py b/src/py4vasp/_third_party/graph/plot.py index 94ef0522..fa89a10e 100644 --- a/src/py4vasp/_third_party/graph/plot.py +++ b/src/py4vasp/_third_party/graph/plot.py @@ -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) diff --git a/tests/third_party/graph/test_plot.py b/tests/third_party/graph/test_plot.py index 11d289ab..3a424d3d 100644 --- a/tests/third_party/graph/test_plot.py +++ b/tests/third_party/graph/test_plot.py @@ -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():