Skip to content

Commit

Permalink
Fix issue when subsetting empty GenomicRanges[List] (#59).
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche authored Jan 4, 2024
1 parent 99fb4be commit b2a4681
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/genomicranges/GenomicRanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,9 @@ def get_subset(self, subset: Union[str, int, bool, Sequence]) -> "GenomicRanges"
Returns:
A new ``GenomicRanges`` object with the ranges of interest.
"""
if len(self) == 0:
return GenomicRanges.empty()

idx, _ = ut.normalize_subscript(subset, len(self), self._names)

current_class_const = type(self)
Expand Down
8 changes: 7 additions & 1 deletion src/genomicranges/GenomicRangesList.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,13 @@ def __str__(self) -> str:
output = (
f"GenomicRangesList with {len(self)} range{'s' if len(self) != 1 else ''}"
)
output += f" and {len(self._mcols)} metadata column{'s' if len(self._mcols) != 1 else ''}\n \n"
output += f" and {len(self._mcols)} metadata column{'s' if len(self._mcols) != 1 else ''}\n"

if isinstance(self._ranges, GenomicRanges) and len(self._ranges) == 0:
output += "--- empty genomic ranges list ---"
return output

output += " \n"

nr = len(self)
added_table = False
Expand Down
4 changes: 4 additions & 0 deletions tests/test_grl_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,7 @@ def test_empty_grl_slice():
subset = grl[0:10]
assert isinstance(subset, GenomicRangesList)
assert len(subset) == 10

subset = grl[[1, 2, 3]]
assert isinstance(subset, GenomicRangesList)
assert len(subset) == 3

0 comments on commit b2a4681

Please sign in to comment.