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

str function for mapbase #4464

Merged
merged 8 commits into from Sep 26, 2020
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
1 change: 1 addition & 0 deletions changelog/4464.trivial.rst
@@ -0,0 +1 @@
Improved the output when you print a sunpy Map.
5 changes: 4 additions & 1 deletion sunpy/map/mapbase.py
Expand Up @@ -254,8 +254,11 @@ def _text_summary(self):
self._reference_latitude)),
tmf=TIME_FORMAT)

def __str__(self):
return f"{self._text_summary()}\n{self.data.__repr__()}"

def __repr__(self):
return object.__repr__(self) + "\n" + self._text_summary() + "\n" + self.data.__repr__()
return f"{object.__repr__(self)}\n{self}"

def _repr_html_(self):
"""
Expand Down
9 changes: 9 additions & 0 deletions sunpy/map/tests/test_mapbase.py
Expand Up @@ -1101,3 +1101,12 @@ def test_contour(simple_map):
assert contour.obstime == simple_map.date
assert u.allclose(contour.Tx, [0, -1, 0, 1, 0] * u.arcsec, atol=1e-10 * u.arcsec)
assert u.allclose(contour.Ty, [0.5, 0, -0.5, 0, 0.5] * u.arcsec, atol=1e-10 * u.arcsec)


def test_print_map(generic_map):
out_repr = generic_map.__repr__()
assert isinstance(out_repr, str)
nabobalis marked this conversation as resolved.
Show resolved Hide resolved
assert object.__repr__(generic_map) in out_repr
out_str = generic_map.__str__()
assert isinstance(out_str, str)
nabobalis marked this conversation as resolved.
Show resolved Hide resolved
assert out_str in out_repr