Skip to content

Commit

Permalink
No warnings from ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
paddyroddy committed Sep 18, 2024
1 parent 1267516 commit 6c936e1
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 14 deletions.
2 changes: 2 additions & 0 deletions glass/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""GLASS package."""

import contextlib

with contextlib.suppress(ModuleNotFoundError):
Expand Down
2 changes: 1 addition & 1 deletion glass/core/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def nnls(
maxiter = 3 * n

index = np.arange(n)
p = np.full(n, False)
p = np.full(n, fill_value=False)
x = np.zeros(n)
for _ in range(maxiter):
if np.all(p):
Expand Down
2 changes: 1 addition & 1 deletion glass/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def broadcast_leading_axes(*args):
return (dims, *arrs)


def ndinterp(x, xp, fp, axis=-1, left=None, right=None, period=None):
def ndinterp(x, xp, fp, axis=-1, left=None, right=None, period=None): # noqa: PLR0913
"""Interpolate multi-dimensional array over axis."""
return np.apply_along_axis(
partial(np.interp, x, xp),
Expand Down
7 changes: 5 additions & 2 deletions glass/ext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
"""


def _extend_path(path, name):
def _extend_path(path, name) -> list:
import os.path
from pkgutil import extend_path

_pkg, _, _mod = name.partition(".")

return list(
filter(os.path.isdir, (os.path.join(p, _mod) for p in extend_path(path, _pkg))),
filter(
os.path.isdir,
(os.path.join(p, _mod) for p in extend_path(path, _pkg)), # noqa: PTH118
)
)


Expand Down
5 changes: 3 additions & 2 deletions glass/lensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ def from_convergence( # noqa: PLR0913

# compute deflection alms in place
fl = np.sqrt(l * (l + 1))
# TODO: missing spin-1 pixel window function here
# TODO(ntessore): missing spin-1 pixel window function here # noqa: FIX002
# https://github.com/glass-dev/glass/issues/243
hp.almxfl(alm, fl, inplace=True)

# if deflection is requested, compute spin-1 maps and add to output
Expand Down Expand Up @@ -253,7 +254,7 @@ def shear_from_convergence(
blm = np.zeros_like(alm)

# factor to convert convergence alm to shear alm
l = np.arange(lmax + 1)
l = np.arange(lmax + 1) # noqa: E741
fl = np.sqrt((l + 2) * (l + 1) * l * (l - 1))
fl /= np.clip(l * (l + 1), 1, None)
fl *= -1
Expand Down
4 changes: 2 additions & 2 deletions glass/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def loglinear_bias(delta, b):
return delta_g


def positions_from_delta(
def positions_from_delta( # noqa: PLR0912, PLR0913, PLR0915
ngal,
delta,
bias=None,
Expand Down Expand Up @@ -163,7 +163,7 @@ def positions_from_delta(
bias_model = globals()[f"{bias_model}_bias"]
elif not callable(bias_model):
msg = "bias_model must be string or callable"
raise ValueError(msg)
raise TypeError(msg)

# broadcast inputs to common shape of extra dimensions
inputs = [(ngal, 0), (delta, 1)]
Expand Down
10 changes: 6 additions & 4 deletions glass/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, fits, ext=None) -> None:
self.ext = ext

def _append(self, data, names=None) -> None:
"""Internal method where the FITS writing is done."""
"""Write the FITS file."""
if self.ext is None or self.ext not in self.fits:
self.fits.write_table(data, names=names, extname=self.ext)
if self.ext is None:
Expand All @@ -75,7 +75,7 @@ def _append(self, data, names=None) -> None:

def write(self, data=None, /, **columns) -> None:
"""
Writes to FITS by calling the internal _append method.
Write to FITS by calling the internal _append method.
Pass either a positional variable (data)
or multiple named arguments (**columns)
Expand All @@ -93,8 +93,10 @@ def write(self, data=None, /, **columns) -> None:
@contextmanager
def write_catalog(filename, *, ext=None):
"""
Write a catalogue into a FITS file, where *ext* is the optional
name of the extension. To be used as a context manager::
Write a catalogue into a FITS file.
Where *ext* is the optional name of the extension.
To be used as a context manager::
# create the catalogue writer
with write_catalog("catalog.fits") as out:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ lint.ignore = [
"ANN201", # TEMPORARY
"COM812", # missing-trailing-comma (ruff-format recommended)
"D203", # one-blank-line-before-class
"D205", # TEMPORARY
"D212", # blank-line-before-class
"ERA001", # TODO: commented-out-code
"ISC001", # single-line-implicit-string-concatenation (ruff-format recommended)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ def test_write_exception(tmp_path):
for i in range(my_max):
if i == except_int:
msg = "Unhandled exception"
raise Exception(msg)
raise Exception(msg) # noqa: TRY002, TRY301
array = np.arange(i, i + 1, delta) # array of size 1/delta
array2 = np.arange(i + 1, i + 2, delta) # array of size 1/delta
out.write(RA=array, RB=array2)

except Exception:
except Exception: # noqa: BLE001
import fitsio

with fitsio.FITS(d / filename) as hdul:
Expand Down

0 comments on commit 6c936e1

Please sign in to comment.