Skip to content

Commit 528eea0

Browse files
committed
Formatting fixes from ruff
1 parent 1babb1f commit 528eea0

File tree

8 files changed

+36
-37
lines changed

8 files changed

+36
-37
lines changed

tests/test_regions.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Optional
2-
31
import pytest
42

53
from vcztools.regions import parse_region_string
@@ -15,6 +13,6 @@
1513
],
1614
)
1715
def test_parse_region_string(
18-
targets: str, expected: tuple[str, Optional[int], Optional[int]]
16+
targets: str, expected: tuple[str, int | None, int | None]
1917
):
2018
assert parse_region_string(targets) == expected

tests/test_vcf_writer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_write_vcf__filtering(tmp_path, include, exclude, expected_chrom_pos):
8585
assert len(variants) == len(expected_chrom_pos)
8686
assert v.samples == ["NA00001", "NA00002", "NA00003"]
8787

88-
for variant, chrom_pos in zip(variants, expected_chrom_pos):
88+
for variant, chrom_pos in zip(variants, expected_chrom_pos, strict=False):
8989
chrom, pos = chrom_pos
9090
assert variant.CHROM == chrom
9191
assert variant.POS == pos
@@ -141,7 +141,7 @@ def test_write_vcf__regions(tmp_path, regions, targets,
141141

142142
assert v.samples == ["NA00001", "NA00002", "NA00003"]
143143

144-
for variant, chrom_pos in zip(variants, expected_chrom_pos):
144+
for variant, chrom_pos in zip(variants, expected_chrom_pos, strict=False):
145145
chrom, pos = chrom_pos
146146
assert variant.CHROM == chrom
147147
assert variant.POS == pos
@@ -230,7 +230,7 @@ def test_write_vcf__regions_samples_filtering(
230230
assert len(variants) == len(expected_chrom_pos)
231231
assert v.samples == ["NA00001"]
232232

233-
for variant, chrom_pos in zip(variants, expected_chrom_pos):
233+
for variant, chrom_pos in zip(variants, expected_chrom_pos, strict=False):
234234
chrom, pos = chrom_pos
235235
assert variant.CHROM == chrom
236236
assert variant.POS == pos

vcztools/filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import functools
22
import operator
3-
from typing import Callable
3+
from collections.abc import Callable
44

55
import numpy as np
66
import pyparsing as pp

vcztools/query.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import functools
22
import itertools
33
import math
4-
from typing import Callable, Optional, Union
4+
from collections.abc import Callable
55

66
import numpy as np
77
import pyparsing as pp
@@ -62,10 +62,10 @@ def __call__(self, *args, **kwargs):
6262
class QueryFormatGenerator:
6363
def __init__(
6464
self,
65-
query_format: Union[str, pp.ParseResults],
65+
query_format: str | pp.ParseResults,
6666
*,
67-
include: Optional[str] = None,
68-
exclude: Optional[str] = None,
67+
include: str | None = None,
68+
exclude: str | None = None,
6969
):
7070
if isinstance(query_format, str):
7171
parser = QueryFormatParser()
@@ -99,7 +99,7 @@ def generate(root):
9999
end = start + v_chunk_size
100100

101101
for gt_row, phase in zip(
102-
gt_zarray[start:end], phase_zarray[start:end]
102+
gt_zarray[start:end], phase_zarray[start:end], strict=False
103103
):
104104

105105
def stringify(gt_and_phase: tuple):
@@ -113,7 +113,7 @@ def stringify(gt_and_phase: tuple):
113113
return separator.join(gt)
114114

115115
gt_row = gt_row.tolist()
116-
yield map(stringify, zip(gt_row, phase))
116+
yield map(stringify, zip(gt_row, phase, strict=False))
117117
else:
118118
# TODO: Support datasets without the phasing data
119119
raise NotImplementedError
@@ -219,8 +219,8 @@ def _compose_sample_loop_generator(
219219

220220
def generate(root):
221221
iterables = (generator(root) for generator in generators)
222-
zipped = zip(*iterables)
223-
zipped_zipped = (zip(*element) for element in zipped)
222+
zipped = zip(*iterables, strict=False)
223+
zipped_zipped = (zip(*element, strict=False) for element in zipped)
224224
flattened_zipped_zipped = (
225225
(
226226
subsubelement
@@ -234,7 +234,7 @@ def generate(root):
234234
return generate
235235

236236
def _compose_element_generator(
237-
self, element: Union[str, pp.ParseResults], *, sample_loop=False
237+
self, element: str | pp.ParseResults, *, sample_loop=False
238238
) -> Callable:
239239
if isinstance(element, pp.ParseResults):
240240
if element.get_name() == "subfield":
@@ -261,7 +261,7 @@ def generate(root):
261261
return generate
262262

263263
def _compose_filter_generator(
264-
self, *, include: Optional[str] = None, exclude: Optional[str] = None
264+
self, *, include: str | None = None, exclude: str | None = None
265265
) -> Callable:
266266
assert not (include and exclude)
267267

@@ -294,8 +294,8 @@ def _compose_generator(
294294
self,
295295
parse_results: pp.ParseResults,
296296
*,
297-
include: Optional[str] = None,
298-
exclude: Optional[str] = None,
297+
include: str | None = None,
298+
exclude: str | None = None,
299299
) -> Callable:
300300
generators = (
301301
self._compose_element_generator(element) for element in parse_results
@@ -308,7 +308,9 @@ def generate(root) -> str:
308308
iterables = (generator(root) for generator in generators)
309309
filter_iterable = filter_generator(root)
310310

311-
for results, filter_indicator in zip(zip(*iterables), filter_iterable):
311+
for results, filter_indicator in zip(
312+
zip(*iterables, strict=False), filter_iterable, strict=False
313+
):
312314
if filter_indicator:
313315
results = map(str, results)
314316
yield "".join(results)
@@ -321,8 +323,8 @@ def write_query(
321323
output=None,
322324
*,
323325
query_format: str,
324-
include: Optional[str] = None,
325-
exclude: Optional[str] = None,
326+
include: str | None = None,
327+
exclude: str | None = None,
326328
):
327329
if include and exclude:
328330
raise ValueError(

vcztools/regions.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import re
2-
from typing import Any, Optional
2+
from typing import Any
33

44
import numcodecs
55
import numpy as np
@@ -52,7 +52,7 @@ def create_index(vcz) -> None:
5252
)
5353

5454

55-
def parse_region_string(region: str) -> tuple[str, Optional[int], Optional[int]]:
55+
def parse_region_string(region: str) -> tuple[str, int | None, int | None]:
5656
"""Return the contig, start position and end position from a region string."""
5757
if re.search(r":\d+-\d*$", region):
5858
contig, start_end = region.rsplit(":", 1)
@@ -67,7 +67,7 @@ def parse_region_string(region: str) -> tuple[str, Optional[int], Optional[int]]
6767

6868

6969
def regions_to_pyranges(
70-
regions: list[tuple[str, Optional[int], Optional[int]]], all_contigs: list[str]
70+
regions: list[tuple[str, int | None, int | None]], all_contigs: list[str]
7171
) -> PyRanges:
7272
"""Convert region tuples to a PyRanges object."""
7373

@@ -90,7 +90,7 @@ def regions_to_pyranges(
9090
return PyRanges(chromosomes=chromosomes, starts=starts, ends=ends)
9191

9292

93-
def parse_regions(regions: Optional[str], all_contigs: list[str]) -> Optional[PyRanges]:
93+
def parse_regions(regions: str | None, all_contigs: list[str]) -> PyRanges | None:
9494
"""Return a PyRanges object from a comma-separated set of region strings."""
9595
if regions is None:
9696
return None
@@ -100,8 +100,8 @@ def parse_regions(regions: Optional[str], all_contigs: list[str]) -> Optional[Py
100100

101101

102102
def parse_targets(
103-
targets: Optional[str], all_contigs: list[str]
104-
) -> tuple[Optional[PyRanges], bool]:
103+
targets: str | None, all_contigs: list[str]
104+
) -> tuple[PyRanges | None, bool]:
105105
"""Return a PyRanges object from a comma-separated set of region strings,
106106
optionally preceeded by a ^ character to indicate complement."""
107107
if targets is None:
@@ -113,8 +113,8 @@ def parse_targets(
113113

114114

115115
def regions_to_chunk_indexes(
116-
regions: Optional[PyRanges],
117-
targets: Optional[PyRanges],
116+
regions: PyRanges | None,
117+
targets: PyRanges | None,
118118
complement: bool,
119119
regions_index: Any,
120120
):
@@ -158,8 +158,8 @@ def regions_to_chunk_indexes(
158158

159159

160160
def regions_to_selection(
161-
regions: Optional[PyRanges],
162-
targets: Optional[PyRanges],
161+
regions: PyRanges | None,
162+
targets: PyRanges | None,
163163
complement: bool,
164164
variant_contig: Any,
165165
variant_position: Any,

vcztools/stats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def stats(vcz, output):
3838
).astype(np.int64)
3939

4040
for contig, contig_length, nr in zip(
41-
contigs, contig_lengths, num_records_per_contig
41+
contigs, contig_lengths, num_records_per_contig, strict=False
4242
):
4343
if nr > 0:
4444
print(f"{contig}\t{contig_length}\t{nr}", file=output)

vcztools/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def open_file_like(file):
1818
"""A context manager for opening a file path or string (and closing on exit),
1919
or passing a file-like object through."""
2020
with ExitStack() as stack:
21-
if isinstance(file, (str, Path)):
21+
if isinstance(file, str | Path):
2222
file = stack.enter_context(open(file, mode="w"))
2323
yield file
2424

vcztools/vcf_writer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import re
44
import sys
55
from datetime import datetime
6-
from typing import Optional
76

87
import numpy as np
98
import zarr
@@ -89,8 +88,8 @@ def write_vcf(
8988
no_update=None,
9089
samples=None,
9190
drop_genotypes: bool = False,
92-
include: Optional[str] = None,
93-
exclude: Optional[str] = None,
91+
include: str | None = None,
92+
exclude: str | None = None,
9493
) -> None:
9594
"""Convert a dataset to a VCF file.
9695

0 commit comments

Comments
 (0)