Skip to content

Commit

Permalink
Merge pull request #7551 from ayshih/arm
Browse files Browse the repository at this point in the history
Fixed an unnecessary division computation for an unsupported division by a Map
  • Loading branch information
nabobalis committed Apr 5, 2024
2 parents 386e540 + 82def12 commit 5dde579
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
1 change: 1 addition & 0 deletions changelog/7551.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an unnecessary division computation when performing a unsupported division operation using a `~sunpy.map.Map`.
1 change: 1 addition & 0 deletions sunpy/map/mapbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ def __mul__(self, value):
def __rmul__(self, value):
return self.__mul__(value)

@check_arithmetic_compatibility
def __truediv__(self, value):
return self.__mul__(1/value)

Expand Down
17 changes: 4 additions & 13 deletions sunpy/map/tests/test_mapbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
import re
import tempfile
import contextlib

import matplotlib
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -1732,23 +1731,15 @@ def test_map_arithmetic_neg(aia171_test_map):
check_arithmetic_value_and_units(new_map, -aia171_test_map.quantity)


@pytest.mark.parametrize(("value", "warn_context"), [
('map', pytest.warns(RuntimeWarning)),
('foobar', contextlib.nullcontext()),
(None, contextlib.nullcontext()),
(['foo', 'bar'], contextlib.nullcontext()),
])
def test_map_arithmetic_operations_raise_exceptions(aia171_test_map, value, warn_context):
@pytest.mark.parametrize("value", ['map', 'foobar', None, ['foo', 'bar']])
def test_map_arithmetic_operations_raise_exceptions(aia171_test_map, value):
value = aia171_test_map if value == 'map' else value
with pytest.raises(TypeError):
_ = aia171_test_map + value
with pytest.raises(TypeError):
_ = aia171_test_map * value
with pytest.raises(TypeError): # NOQA: PT012
# A runtime warning is thrown when dividing by zero in the case of
# the map test
with warn_context:
_ = value / aia171_test_map
with pytest.raises(TypeError):
_ = value / aia171_test_map


def test_parse_fits_units():
Expand Down

0 comments on commit 5dde579

Please sign in to comment.