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

Raise error when plotting a potential with both xy=True and effective=True #587

Merged
merged 1 commit into from Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions galpy/potential/Potential.py
Expand Up @@ -1033,6 +1033,8 @@
2014-04-08 - Added effective= - Bovy (IAS)

"""
if effective and xy:
raise RuntimeError("xy and effective cannot be True at the same time")

Check warning on line 1037 in galpy/potential/Potential.py

View check run for this annotation

Codecov / codecov/patch

galpy/potential/Potential.py#L1037

Added line #L1037 was not covered by tests
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 @@
2010-07-09 - Written - Bovy (NYU)

"""
if effective and xy:
raise RuntimeError("xy and effective cannot be True at the same time")

Check warning on line 3068 in galpy/potential/Potential.py

View check run for this annotation

Codecov / codecov/patch

galpy/potential/Potential.py#L3068

Added line #L3068 was not covered by tests
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
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