Skip to content

Commit

Permalink
Fix export to pandas dataframe (#15)
Browse files Browse the repository at this point in the history
Add tests as well
  • Loading branch information
jkanche authored Dec 1, 2023
1 parent 36b908c commit 54621ff
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ install_requires =
biocutils>=0.1.2,<0.2.0
biocframe>=0.5.3,<0.6.0
numpy

ncls==0.0.68

[options.packages.find]
where = src
Expand All @@ -64,7 +64,7 @@ exclude =
# `pip install IRanges[PDF]` like:
# PDF = ReportLab; RXP
optional =
ncls==0.0.68
numpy

# Add here test requirements (semicolon/line-separated)
testing =
Expand Down
4 changes: 2 additions & 2 deletions src/iranges/IRanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -2082,7 +2082,7 @@ def to_pandas(self) -> "pandas.DataFrame":

_starts = self._start
_widths = self._width
_ends = self.get_end
_ends = self.get_end()

output = pd.DataFrame({"starts": _starts, "widths": _widths, "ends": _ends})

Expand All @@ -2100,7 +2100,7 @@ def from_pandas(cls, input: "pandas.DataFrame") -> "IRanges":
Args:
input:
Input data. must contain columns 'start' and 'width'.
Input data must contain columns 'start' and 'width'.
Returns:
A ``IRanges`` object.
Expand Down
9 changes: 9 additions & 0 deletions tests/test_IRanges_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ def test_pandas():
assert (x.get_start() == np.array(df["start"])).all()
assert (x.get_width() == np.array(df["width"])).all()
assert isinstance(x.mcols, BiocFrame)


def test_pandas_export():
x = IRanges([1, 2, 3, 4], [4, 5, 6, 7])

y = x.to_pandas()
assert y is not None
assert isinstance(y, pd.DataFrame)
assert set(y.columns.tolist()).issubset(["starts", "ends", "widths"])

0 comments on commit 54621ff

Please sign in to comment.