Skip to content

Commit

Permalink
create an empty iranges object
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed Nov 29, 2023
1 parent 14ff5c9 commit 80301d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/iranges/IRanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -2132,6 +2132,15 @@ def from_pandas(cls, input: "pandas.DataFrame") -> "IRanges":

return cls(start=start, width=width, names=names, mcols=mcols)

@classmethod
def empty(cls):
"""Create an zero-length ``IRanges`` object.
Returns:
same type as caller, in this case a ``IRanges``.
"""
return cls([], [])


@combine_sequences.register
def _combine_IRanges(*x: IRanges) -> IRanges:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_IRanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,10 @@ def test_IRanges_combine():
y = IRanges(starts2, widths2, names=["A", "B", "C", "D"])
comb = combine_sequences(x, y)
assert comb.get_names() == ["", "", "", "", "A", "B", "C", "D"]


def test_empty():
r = IRanges.empty()

assert r is not None
assert isinstance(r, IRanges)

0 comments on commit 80301d4

Please sign in to comment.