Skip to content

Commit

Permalink
Raise error when plotting a potential with both xy=True and effective…
Browse files Browse the repository at this point in the history
…=True; fixes #572
  • Loading branch information
jobovy committed Jun 21, 2023
1 parent 6928fe8 commit a209b51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions galpy/potential/Potential.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,8 @@ def plot(
2014-04-08 - Added effective= - Bovy (IAS)
"""
if effective and xy:
raise RuntimeError("xy and effective cannot be True at the same time")
rmin = conversion.parse_length(rmin, ro=self._ro)
rmax = conversion.parse_length(rmax, ro=self._ro)
zmin = conversion.parse_length(zmin, ro=self._ro)
Expand Down Expand Up @@ -3062,6 +3064,8 @@ def plotPotentials(
2010-07-09 - Written - Bovy (NYU)
"""
if effective and xy:
raise RuntimeError("xy and effective cannot be True at the same time")
Pot = flatten(Pot)
rmin = conversion.parse_length(rmin, **get_physical(Pot))
rmax = conversion.parse_length(rmax, **get_physical(Pot))
Expand Down
14 changes: 14 additions & 0 deletions tests/test_potential.py
Original file line number Diff line number Diff line change
Expand Up @@ -7582,6 +7582,20 @@ def test_InterpSnapshotRZPotential_pickling():
return None


# Test that trying to plot a potential with xy=True and effective=True raises a RuntimeError
def test_plotting_xy_effective_error():
# First a single potential
kp = potential.KeplerPotential(normalize=1.0)
with pytest.raises(RuntimeError) as excinfo:
kp.plot(xy=True, effective=True)
assert "xy and effective cannot be True at the same time" in excinfo.value.args[0]
# Then a list of potentials
with pytest.raises(RuntimeError) as excinfo:
potential.plotPotentials(potential.MWPotential2014, xy=True, effective=True)
assert "xy and effective cannot be True at the same time" in excinfo.value.args[0]
return None


def test_plotting():
import tempfile

Expand Down

0 comments on commit a209b51

Please sign in to comment.