Skip to content

Commit c03be35

Browse files
committed
Fix new ruff rules
1 parent e0a5014 commit c03be35

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

ndcube/ndcube.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,8 @@ def reproject_to(self,
796796
However, ``meta`` and ``global_coords`` are copied to the output `ndcube.NDCube`.
797797
"""
798798
try:
799-
from reproject import reproject_adaptive, reproject_exact, reproject_interp
800-
from reproject.wcs_utils import has_celestial
799+
from reproject import reproject_adaptive, reproject_exact, reproject_interp # noqa: PLC0415
800+
from reproject.wcs_utils import has_celestial # noqa: PLC0415
801801
except ModuleNotFoundError:
802802
raise ImportError(f"The {type(self).__name__}.reproject_to method requires "
803803
f"the `reproject` library to be installed.")
@@ -923,7 +923,7 @@ def _as_mpl_axes(self):
923923
warn_user(f"The current plotter {self.plotter} does not have a '_as_mpl_axes' method. "
924924
"The default MatplotlibPlotter._as_mpl_axes method will be used instead.")
925925

926-
from ndcube.visualization.mpl_plotter import MatplotlibPlotter
926+
from ndcube.visualization.mpl_plotter import MatplotlibPlotter # noqa: PLC0415
927927

928928
plotter = MatplotlibPlotter(self)
929929
return plotter._as_mpl_axes()

ndcube/tests/test_ndcube_arithmetic.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ def test_cube_arithmetic_rdivide(ndcube_2d_ln_lt_units, value):
241241
@pytest.mark.parametrize('value', [1, 2, -1])
242242
def test_cube_arithmetic_rdivide_uncertainty(ndcube_4d_unit_uncertainty, value):
243243
cube_quantity = u.Quantity(ndcube_4d_unit_uncertainty.data, ndcube_4d_unit_uncertainty.unit)
244-
with pytest.warns(NDCubeUserWarning, match="UnknownUncertainty does not support uncertainty propagation with correlation. Setting uncertainties to None."):
244+
match = "UnknownUncertainty does not support uncertainty propagation with correlation. Setting uncertainties to None."
245+
with pytest.warns(NDCubeUserWarning, match=match): # noqa: PT031
245246
with np.errstate(divide='ignore'):
246247
new_cube = value / ndcube_4d_unit_uncertainty
247248
check_arithmetic_value_and_units(new_cube, value / cube_quantity)
@@ -280,7 +281,8 @@ def test_cube_arithmetic_power(ndcube_2d_ln_lt, power):
280281
@pytest.mark.parametrize('power', [2, -2, 10, 0.5])
281282
def test_cube_arithmetic_power_unknown_uncertainty(ndcube_4d_unit_uncertainty, power):
282283
cube_quantity = u.Quantity(ndcube_4d_unit_uncertainty.data, ndcube_4d_unit_uncertainty.unit)
283-
with pytest.warns(NDCubeUserWarning, match="UnknownUncertainty does not support uncertainty propagation with correlation. Setting uncertainties to None."):
284+
match = "UnknownUncertainty does not support uncertainty propagation with correlation. Setting uncertainties to None."
285+
with pytest.warns(NDCubeUserWarning, match=match): # noqa: PT031
284286
with np.errstate(divide='ignore'):
285287
new_cube = ndcube_4d_unit_uncertainty ** power
286288
check_arithmetic_value_and_units(new_cube, cube_quantity**power)
@@ -289,7 +291,8 @@ def test_cube_arithmetic_power_unknown_uncertainty(ndcube_4d_unit_uncertainty, p
289291
@pytest.mark.parametrize('power', [2, -2, 10, 0.5])
290292
def test_cube_arithmetic_power_std_uncertainty(ndcube_2d_ln_lt_uncert, power):
291293
cube_quantity = u.Quantity(ndcube_2d_ln_lt_uncert.data, ndcube_2d_ln_lt_uncert.unit)
292-
with pytest.warns(NDCubeUserWarning, match=r"<class 'astropy.nddata.nduncertainty.StdDevUncertainty'> does not support propagation of uncertainties for power. Setting uncertainties to None."):
294+
match = r"<class 'astropy.nddata.nduncertainty.StdDevUncertainty'> does not support propagation of uncertainties for power. Setting uncertainties to None."
295+
with pytest.warns(NDCubeUserWarning, match=match): # noqa: PT031
293296
with np.errstate(divide='ignore'):
294297
new_cube = ndcube_2d_ln_lt_uncert ** power
295298
check_arithmetic_value_and_units(new_cube, cube_quantity**power)

ndcube/utils/cube.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def sanitize_wcs(func):
3030
passed is a HighLevelWCS object, or an ExtraCoords object.
3131
"""
3232
# This needs to be here to prevent a circular import
33-
from ndcube.extra_coords.extra_coords import ExtraCoords
33+
from ndcube.extra_coords.extra_coords import ExtraCoords # noqa: PLC0415
3434

3535
@wraps(func)
3636
def wcs_wrapper(*args, **kwargs):
@@ -92,7 +92,7 @@ def sanitize_crop_inputs(points, wcs):
9292
raise ValueError("All points must have same number of coordinate objects."
9393
f"Number of objects in each point: {n_coords}")
9494
# Import must be here to avoid circular import.
95-
from ndcube.extra_coords.extra_coords import ExtraCoords
95+
from ndcube.extra_coords.extra_coords import ExtraCoords # noqa: PLC0415
9696
if isinstance(wcs, ExtraCoords):
9797
# Determine how many dummy axes are needed
9898
n_dummy_axes = len(wcs._cube_array_axes_without_extra_coords)

ndcube/visualization/descriptor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ def _resolve_default_type(self, raise_error=True):
3535
if self._default_type in ("mpl_plotter", "mpl_sequence_plotter"):
3636
if self._default_type == "mpl_plotter":
3737
try:
38-
from ndcube.visualization.mpl_plotter import MatplotlibPlotter
38+
from ndcube.visualization.mpl_plotter import MatplotlibPlotter # noqa: PLC0415
3939
return MatplotlibPlotter
4040
except ImportError as e:
4141
if raise_error:
4242
raise ImportError(MISSING_MATPLOTLIB_ERROR_MSG) from e
4343
elif self._default_type == "mpl_sequence_plotter":
4444
try:
45-
from ndcube.visualization.mpl_sequence_plotter import MatplotlibSequencePlotter
45+
from ndcube.visualization.mpl_sequence_plotter import \
46+
MatplotlibSequencePlotter # noqa: PLC0415
4647
return MatplotlibSequencePlotter
4748
except ImportError as e:
4849
if raise_error:

ndcube/visualization/mpl_plotter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def _plot_2D_cube(self, wcs, axes=None, plot_axes=None, axes_coordinates=None,
196196
def _animate_cube(self, wcs, plot_axes=None, axes_coordinates=None,
197197
axes_units=None, data_unit=None, **kwargs):
198198
try:
199-
from mpl_animators import ArrayAnimatorWCS
199+
from mpl_animators import ArrayAnimatorWCS # noqa: PLC0415
200200
except ImportError as e:
201201
raise ImportError(MISSING_ANIMATORS_ERROR_MSG) from e
202202

ndcube/wcs/wrappers/compound_wcs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def world_to_pixel_values(self, *world_arrays):
148148
def world_axis_object_components(self):
149149
all_components = []
150150
for iw, w in enumerate(self._wcs):
151-
all_components += [(f'{component[0]}_{iw}',) + component[1:] for component
151+
all_components += [(f'{component[0]}_{iw}', *component[1:]) for component
152152
in w.world_axis_object_components]
153153
return all_components
154154

0 commit comments

Comments
 (0)