Skip to content

Commit

Permalink
style: Fix bugbear errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nvictus committed May 21, 2024
1 parent 59d45b2 commit 116cf11
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 21 deletions.
4 changes: 2 additions & 2 deletions docs/make_cli_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _write_opts(opts):
if opt.default is not None and opt.show_default:
extra.append(
"default: {}".format(
", ".join("%s" % d for d in opt.default)
", ".join(f"{d}" for d in opt.default)
if isinstance(opt.default, (list, tuple))
else opt.default
)
Expand Down Expand Up @@ -161,7 +161,7 @@ def _format_envvar(param):

def _format_envvars(ctx):
"""Format all envvars for a `click.Command`."""
params = [x for x in ctx.command.params if getattr(x, "envvar")]
params = [x for x in ctx.command.params if x.envvar]

for param in params:
yield ".. _{command_name}-{param_name}-{envvar}:".format(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ cooler = "cooler.cli:cli"
path = "src/cooler/_version.py"

[tool.ruff]
src = ["src"]
exclude = [
".venv",
"__init__.py",
Expand Down
9 changes: 7 additions & 2 deletions src/cooler/balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ def _balance_genomewide(
break
else:
warnings.warn(
"Iteration limit reached without convergence.", ConvergenceWarning
"Iteration limit reached without convergence.",
ConvergenceWarning,
stacklevel=1,
)

scale = nzmarg.mean()
Expand Down Expand Up @@ -180,6 +182,7 @@ def _balance_cisonly(
warnings.warn(
f"Iteration limit reached without convergence on {chroms[cid]}.",
ConvergenceWarning,
stacklevel=1,
)

scale = nzmarg.mean()
Expand Down Expand Up @@ -244,7 +247,9 @@ def _balance_transonly(
break
else:
warnings.warn(
"Iteration limit reached without convergence.", ConvergenceWarning
"Iteration limit reached without convergence.",
ConvergenceWarning,
stacklevel=1,
)

scale = nzmarg.mean()
Expand Down
3 changes: 2 additions & 1 deletion src/cooler/cli/zoomify.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ def zoomify(
if "n" in res or "b" in res and maxres < curres:
warnings.warn(
"Map is already < 256 x 256. Provide resolutions "
"explicitly if you want to coarsen more."
"explicitly if you want to coarsen more.",
stacklevel=1,
)
if res == "n":
r = preferred_sequence(curres, maxres, "nice")
Expand Down
6 changes: 3 additions & 3 deletions src/cooler/core/_rangequery.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def sparray_slice_from_dict(
raise ImportError(
"The 'sparse' package is required for pydata/sparse output. "
"You can install it with 'pip install sparse'."
)
) from None

shape = (row_stop - row_start, col_stop - col_start)
return COO(
Expand Down Expand Up @@ -355,7 +355,7 @@ def to_delayed(self) -> list:
except ImportError:
raise ImportError(
"The 'dask' package is required for `dask.delayed` output."
)
) from None

out = []
for task in self.tasks:
Expand Down Expand Up @@ -383,7 +383,7 @@ def to_dask_frame(self) -> Any:
raise ImportError(
"The 'dask' package is required for dask DataFrame output. "
"Install dask[dataframe] or dask[complete] with pip."
)
) from None

meta = self.reader.get_frame_meta(self.field)
tasks = self.tasks
Expand Down
7 changes: 5 additions & 2 deletions src/cooler/create/_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ def _get_dtypes_arg(
if "dtype" in kwargs:
if dtypes is None:
dtypes = kwargs.pop("dtype")
warnings.warn("Use dtypes= instead of dtype=", FutureWarning)
warnings.warn(
"Use dtypes= instead of dtype=", FutureWarning, stacklevel=2
)
else:
raise ValueError(
'Received both "dtypes" and "dtype" arguments. '
Expand Down Expand Up @@ -593,7 +595,8 @@ def create(
if not symmetric_upper and triucheck:
warnings.warn(
"Creating a non-symmetric matrix, but `triucheck` was set to "
"True. Changing to False."
"True. Changing to False.",
stacklevel=2,
)
triucheck = False

Expand Down
19 changes: 14 additions & 5 deletions src/cooler/create/_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,13 +691,15 @@ def __init__(
for chrom in self.gs.contigs:
if chrom not in self.file_contigs:
warnings.warn(
"Did not find contig " + f" '{chrom}' in contact list file."
"Did not find contig " + f" '{chrom}' in contact list file.",
stacklevel=2,
)

warnings.warn(
"NOTE: When using the Tabix aggregator, make sure the order of "
"chromosomes in the provided chromsizes agrees with the chromosome "
"ordering of read ends in the contact list file."
"ordering of read ends in the contact list file.",
stacklevel=2,
)

def aggregate(
Expand Down Expand Up @@ -871,7 +873,8 @@ def __init__(
for chrom in self.gs.contigs:
if chrom not in self.file_contigs:
warnings.warn(
"Did not find contig " + f" '{chrom}' in contact list file."
"Did not find contig " + f" '{chrom}' in contact list file.",
stacklevel=2,
)

def aggregate(
Expand Down Expand Up @@ -991,7 +994,10 @@ def select_block(self, chrom1, chrom2):
try:
block = self.mapping[chrom2, chrom1].T
except KeyError:
warnings.warn(f"Block for {{{chrom1}, {chrom2}}} not found")
warnings.warn(
f"Block for {{{chrom1}, {chrom2}}} not found",
stacklevel=2,
)
raise
return block

Expand Down Expand Up @@ -1097,7 +1103,10 @@ def select_block(self, chrom1, chrom2):
try:
block = self.mapping[chrom2, chrom1].T
except KeyError:
warnings.warn(f"Block for {{{chrom1}, {chrom2}}} not found")
warnings.warn(
f"Block for {{{chrom1}, {chrom2}}} not found",
stacklevel=2,
)
raise
return block

Expand Down
10 changes: 8 additions & 2 deletions src/cooler/fileops.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ def _is_cooler(grp: h5py.Group) -> bool:
if fmt == MAGIC:
keys = ("chroms", "bins", "pixels", "indexes")
if not all(name in grp.keys() for name in keys):
warnings.warn(f"Cooler path {grp.name} appears to be corrupt")
warnings.warn(
f"Cooler path {grp.name} appears to be corrupt",
stacklevel=2,
)
return True
return False

Expand Down Expand Up @@ -172,7 +175,10 @@ def is_scool_file(filepath: str) -> bool:
if fmt == MAGIC_SCOOL:
keys = ("chroms", "bins", "cells")
if not all(name in f.keys() for name in keys):
warnings.warn("Scool file appears to be corrupt")
warnings.warn(
"Scool file appears to be corrupt",
stacklevel=2,
)
return False
if "cells" in f.keys() and len(f["cells"].keys()) > 0:
for cells in f["cells"].keys():
Expand Down
3 changes: 2 additions & 1 deletion src/cooler/reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ def merge_breakpoints(
if n_over > 0:
warnings.warn(
f"{n_over} merge epochs will require buffering more than {bufsize} "
f"pixel records, with as many as {nrecords_per_epoch.max():g}."
f"pixel records, with as many as {nrecords_per_epoch.max():g}.",
stacklevel=2,
)

return bin1_partition, cum_nrecords
Expand Down
4 changes: 1 addition & 3 deletions tests/test_fileops.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,4 @@ def test_list_scool_cells():
]
cell_paths = fileops.list_scool_cells(src_file)
assert len(cell_paths) == 5
for cell in paths:
if cell not in cell_paths:
assert False
assert all([cell in paths for cell in cell_paths])

0 comments on commit 116cf11

Please sign in to comment.