Skip to content

Commit

Permalink
Fix codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Aug 15, 2024
1 parent 7f5b4a4 commit 4378487
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
14 changes: 9 additions & 5 deletions astropy/coordinates/angles/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,12 +617,16 @@ def _validate_angles(self, angles=None):

if np.any(np.abs(angles_view) > limit):
if np.size(angles) < 5:
raise ValueError("Latitude angle(s) must be within -90 deg <= angle "
f"<= 90 deg, got {angles.to(u.degree)}")
raise ValueError(
"Latitude angle(s) must be within -90 deg <= angle "
f"<= 90 deg, got {angles.to(u.degree)}"
)
else:
raise ValueError("Latitude angle(s) must be within -90 deg <= angle "
f"<= 90 deg, got {angles.min().to(u.degree)} <= "
f"angle <= {angles.max().to(u.degree)}")
raise ValueError(
"Latitude angle(s) must be within -90 deg <= angle "
f"<= 90 deg, got {angles.min().to(u.degree)} <= "
f"angle <= {angles.max().to(u.degree)}"
)

def __setitem__(self, item, value):
# Forbid assigning a Long to a Lat.
Expand Down
35 changes: 19 additions & 16 deletions astropy/coordinates/tests/test_angles.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,9 +698,9 @@ def test_latitude():

lim_exc = r"Latitude angle\(s\) must be within -90 deg <= angle <= 90 deg, got"
with pytest.raises(ValueError, match=rf"{lim_exc} \[91. 89.\] deg"):
Latitude(['91d', '89d'])
Latitude(["91d", "89d"])
with pytest.raises(ValueError, match=f"{lim_exc} -91.0 deg"):
Latitude('-91d')
Latitude("-91d")

lat = Latitude(["90d", "89d"])
# check that one can get items
Expand All @@ -721,15 +721,15 @@ def test_latitude():

# Check error message for long-ish input arrays (#13994).
with pytest.raises(
ValueError, match=rf"{lim_exc} -143.239\d* deg <= angle <= 171.887\d* deg"
ValueError, match=rf"{lim_exc} -143.239\d* deg <= angle <= 171.887\d* deg"
):
lat = Latitude([0, 1, 2, 3, -2.5, -1, -0.5] * u.radian)


def test_latitude_manipulation():
"""Test value manipulation operations on Latitude angles."""

lat = Latitude(['90d', '-29d'])
lat = Latitude(["90d", "-29d"])
# conserve type on unit change (closes #1423)
angle = lat.to("radian")
assert type(angle) is Latitude
Expand All @@ -755,24 +755,24 @@ def test_latitude_manipulation():
def test_lon_as_lat():
"""Test validation when trying to interoperate with longitudes."""

lon = Longitude(10, 'deg')
lon = Longitude(10, "deg")
with pytest.raises(
TypeError, match="A Latitude angle cannot be created from a Longitude angle"
TypeError, match="A Latitude angle cannot be created from a Longitude angle"
):
lat = Latitude(lon)

with pytest.raises(
TypeError, match="A Longitude angle cannot be assigned to a Latitude angle"
TypeError, match="A Longitude angle cannot be assigned to a Latitude angle"
):
lat = Latitude([20], 'deg')
lat = Latitude([20], "deg")
lat[0] = lon

# Check we can work around the Lat vs Long checks by casting explicitly to Angle.
lat = Latitude(Angle(lon))
assert lat.value == 10.0

# Check setitem.
lat = Latitude([20], 'deg')
lat = Latitude([20], "deg")
lat[0] = Angle(lon)
assert lat.value[0] == 10.0

Expand Down Expand Up @@ -861,25 +861,25 @@ def test_longitude():
def test_lat_as_lon():
"""Test validation when trying to interoperate with latitudes."""

lat = Latitude(10, 'deg')
lat = Latitude(10, "deg")
# Test errors when trying to interoperate with latitudes.
with pytest.raises(
TypeError, match="A Longitude angle cannot be created from a Latitude angle"
TypeError, match="A Longitude angle cannot be created from a Latitude angle"
):
lon = Longitude(lat)

with pytest.raises(
TypeError, match="A Latitude angle cannot be assigned to a Longitude angle"
TypeError, match="A Latitude angle cannot be assigned to a Longitude angle"
):
lon = Longitude([20], 'deg')
lon = Longitude([20], "deg")
lon[0] = lat

# Check we can work around the Lat vs Long checks by casting explicitly to Angle.
lon = Longitude(Angle(lat))
assert lon.value == 10.0

# Check setitem.
lon = Longitude([20], 'deg')
lon = Longitude([20], "deg")
lon[0] = Angle(lat)
assert lon.value[0] == 10.0

Expand Down Expand Up @@ -1209,8 +1209,11 @@ def test_latitude_out_of_limits(value, dtype):
Test that values slightly larger than pi/2 are rejected for different dtypes.
Test cases for issue #13708
"""
with pytest.raises(ValueError, match=r"Latitude angle\(s\) must be within -90 deg "
r"<= angle <= 90 deg, got -?90.001\d* deg"):
with pytest.raises(
ValueError,
match=r"Latitude angle\(s\) must be within -90 deg "
r"<= angle <= 90 deg, got -?90.001\d* deg",
):
Latitude(value, u.rad, dtype=dtype)


Expand Down

0 comments on commit 4378487

Please sign in to comment.