Skip to content

Commit

Permalink
Fixed ruff errors and bumped RTD Python version to 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Feb 28, 2024
1 parent a3f4759 commit 4e8f8ea
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
build:
os: ubuntu-20.04
tools:
python: "3.9"
python: "3.10"
apt_packages:
- graphviz

Expand Down
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ ignore = [
]

[tool.ruff]

[tool.ruff.lint]
extend-select = [
lint.select = [
"B", # flake8-bugbear
"I", # isort
"UP", # pyupgrade
Expand Down
2 changes: 1 addition & 1 deletion reproject/healpix/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def parse_input_healpix_data(input_data, field=0, hdu_in=None, nested=None):
Parse input HEALPIX data to return a Numpy array and coordinate frame object.
"""

if isinstance(input_data, (TableHDU, BinTableHDU)):
if isinstance(input_data, TableHDU | BinTableHDU):
data = input_data.data
header = input_data.header
coordinate_system_in = parse_coord_system(header["COORDSYS"])
Expand Down
2 changes: 1 addition & 1 deletion reproject/mosaicking/coadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def reproject_and_coadd(
corrections = solve_corrections_sgd(offset_matrix)
if background_reference:
corrections -= corrections[background_reference]
for array, correction in zip(arrays, corrections):
for array, correction in zip(arrays, corrections, strict=True):
array.array -= correction

# At this point, the images are now ready to be co-added.
Expand Down
2 changes: 1 addition & 1 deletion reproject/mosaicking/tests/test_coadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def test_coadd_solar_map():
wcs_out = WCS(Header.fromstring(HEADER_SOLAR_OUT, sep="\n"))
scales = [1 / 6, 1, 1 / 6]

input_data = tuple((a.data * scale, a.wcs) for (a, scale) in zip(maps, scales))
input_data = tuple((a.data * scale, a.wcs) for (a, scale) in zip(maps, scales, strict=True))

array, footprint = reproject_and_coadd(
input_data,
Expand Down
4 changes: 2 additions & 2 deletions reproject/mosaicking/tests/test_wcs_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@ def test_input_types(valid_celestial_input_shapes, iterable):

if (
not isinstance(input_value, WCS)
and isinstance(input_value, (BaseLowLevelWCS, BaseHighLevelWCS))
and isinstance(input_value, BaseLowLevelWCS | BaseHighLevelWCS)
) or (
isinstance(input_value, tuple)
and not isinstance(input_value[1], WCS)
and isinstance(input_value[1], (BaseLowLevelWCS, BaseHighLevelWCS))
and isinstance(input_value[1], BaseLowLevelWCS | BaseHighLevelWCS)
):
wcs_ref = WCS(fits.Header.fromstring(APE14_HEADER_REF, sep="\n"))
shape_ref = (31, 50)
Expand Down
4 changes: 2 additions & 2 deletions reproject/mosaicking/wcs_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def find_optimal_celestial_wcs(
iterable = False
elif isiterable(input_data):
if len(input_data) == 2 and isinstance(
input_data[1], (BaseLowLevelWCS, BaseHighLevelWCS, Header)
input_data[1], BaseLowLevelWCS | BaseHighLevelWCS | Header
):
# Since 2-element tuples are valid single inputs we need to check for this
iterable = False
Expand Down Expand Up @@ -245,7 +245,7 @@ def find_optimal_celestial_wcs(
# rectangle
from shapely.geometry import MultiPoint

mp = MultiPoint(list(zip(xp, yp)))
mp = MultiPoint(list(zip(xp, yp, strict=True)))

# The following returns a list of rectangle vertices - in fact there
# are 5 coordinates because shapely represents it as a closed polygon
Expand Down
2 changes: 1 addition & 1 deletion reproject/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_parse_input_data(tmpdir, valid_celestial_input_data, request):
array_ref, wcs_ref, input_value, kwargs = valid_celestial_input_data

data, wcs = parse_input_data(input_value, **kwargs)
assert isinstance(data, (da.Array, np.ndarray))
assert isinstance(data, da.Array | np.ndarray)
np.testing.assert_allclose(data, array_ref)
assert_wcs_allclose(wcs, wcs_ref)

Expand Down
16 changes: 8 additions & 8 deletions reproject/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def parse_input_data(input_data, hdu_in=None):
Parse input data to return a Numpy array and WCS object.
"""

if isinstance(input_data, (str, Path)):
if isinstance(input_data, str | Path):
with fits.open(input_data) as hdul:
return parse_input_data(hdul, hdu_in=hdu_in)
elif isinstance(input_data, HDUList):
Expand All @@ -83,9 +83,9 @@ def parse_input_data(input_data, hdu_in=None):
else:
hdu_in = 0
return parse_input_data(input_data[hdu_in])
elif isinstance(input_data, (PrimaryHDU, ImageHDU, CompImageHDU)):
elif isinstance(input_data, PrimaryHDU | ImageHDU | CompImageHDU):
return input_data.data, WCS(input_data.header)
elif isinstance(input_data, tuple) and isinstance(input_data[0], (np.ndarray, da.core.Array)):
elif isinstance(input_data, tuple) and isinstance(input_data[0], np.ndarray | da.core.Array):
if isinstance(input_data[1], Header):
return input_data[0], WCS(input_data[1])
else:
Expand Down Expand Up @@ -114,7 +114,7 @@ def parse_input_shape(input_shape, hdu_in=None):
Parse input shape information to return an array shape tuple and WCS object.
"""

if isinstance(input_shape, (str, Path)):
if isinstance(input_shape, str | Path):
return parse_input_shape(fits.open(input_shape), hdu_in=hdu_in)
elif isinstance(input_shape, HDUList):
if hdu_in is None:
Expand All @@ -126,9 +126,9 @@ def parse_input_shape(input_shape, hdu_in=None):
else:
hdu_in = 0
return parse_input_shape(input_shape[hdu_in])
elif isinstance(input_shape, (PrimaryHDU, ImageHDU, CompImageHDU)):
elif isinstance(input_shape, PrimaryHDU | ImageHDU | CompImageHDU):
return input_shape.shape, WCS(input_shape.header)
elif isinstance(input_shape, tuple) and isinstance(input_shape[0], (np.ndarray, da.core.Array)):
elif isinstance(input_shape, tuple) and isinstance(input_shape[0], np.ndarray | da.core.Array):
if isinstance(input_shape[1], Header):
return input_shape[0].shape, WCS(input_shape[1])
else:
Expand Down Expand Up @@ -177,7 +177,7 @@ def parse_input_weights(input_weights, hdu_weights=None):
else:
hdu_weights = 0
return parse_input_data(input_weights[hdu_weights])[0]
elif isinstance(input_weights, (PrimaryHDU, ImageHDU, CompImageHDU)):
elif isinstance(input_weights, PrimaryHDU | ImageHDU | CompImageHDU):
return input_weights.data
elif isinstance(input_weights, np.ndarray):
return input_weights
Expand Down Expand Up @@ -205,7 +205,7 @@ def parse_output_projection(output_projection, shape_in=None, shape_out=None, ou
"Need to specify shape since output header "
"does not contain complete shape information"
) from None
elif isinstance(output_projection, (BaseLowLevelWCS, BaseHighLevelWCS)):
elif isinstance(output_projection, BaseLowLevelWCS | BaseHighLevelWCS):
if isinstance(output_projection, BaseLowLevelWCS) and not isinstance(
output_projection, BaseHighLevelWCS
):
Expand Down

0 comments on commit 4e8f8ea

Please sign in to comment.