diff --git a/src/iranges/IRanges.py b/src/iranges/IRanges.py index e13ff26..f8398ef 100644 --- a/src/iranges/IRanges.py +++ b/src/iranges/IRanges.py @@ -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: diff --git a/tests/test_IRanges.py b/tests/test_IRanges.py index 8634c4e..3c95f30 100644 --- a/tests/test_IRanges.py +++ b/tests/test_IRanges.py @@ -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)