Skip to content
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

Improve error msg for plot coils when non-coil object is passed in #1198

Merged
merged 4 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 8 additions & 0 deletions desc/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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"
dpanici marked this conversation as resolved.
Show resolved Hide resolved
f" {type(coils)}",
)

if not isinstance(lw, (list, tuple)):
lw = [lw]
Expand Down
2 changes: 2 additions & 0 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading