From e39d08fc65087c18b8d1b409d55c14cd66cdbb71 Mon Sep 17 00:00:00 2001 From: Dario Panici Date: Fri, 16 Aug 2024 10:42:54 -0400 Subject: [PATCH] improve error msg for plot coilis --- desc/plotting.py | 8 ++++++++ tests/test_plotting.py | 2 ++ 2 files changed, 10 insertions(+) diff --git a/desc/plotting.py b/desc/plotting.py index ba822a5b2b..478e11dc66 100644 --- a/desc/plotting.py +++ b/desc/plotting.py @@ -2384,6 +2384,8 @@ def plot_coils(coils, grid=None, fig=None, return_data=False, **kwargs): dictionary of the data plotted, only returned if ``return_data=True`` """ + from desc.coils import _Coil + lw = kwargs.pop("lw", 5) ls = kwargs.pop("ls", "solid") figsize = kwargs.pop("figsize", (10, 10)) @@ -2394,6 +2396,12 @@ def plot_coils(coils, grid=None, fig=None, return_data=False, **kwargs): ValueError, f"plot_coils got unexpected keyword argument: {kwargs.keys()}", ) + errorif( + not isinstance(coils, _Coil), + ValueError, + "Expected `coils` to be object of type `_Coil`, instead got type" + f" {type(coils)}", + ) if not isinstance(lw, (list, tuple)): lw = [lw] diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 8252d349d8..1351b46c93 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -801,6 +801,8 @@ def test_plot_coils(): coil.rotate(angle=np.pi / N) coils = CoilSet.linspaced_angular(coil, I, [0, 0, 1], np.pi / NFP, N // NFP // 2) coils2 = MixedCoilSet.from_symmetry(coils, NFP, True) + with pytest.raises(ValueError, match="Expected `coils`"): + plot_coils("not a coil") fig, data = plot_coils(coils2, return_data=True) def flatten_coils(coilset):