Skip to content

Commit

Permalink
Fix coercion to pandas when iranges contains mcols
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed Oct 15, 2024
1 parent b6e6f2a commit aab666f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/iranges/IRanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -2220,7 +2220,7 @@ def to_pandas(self) -> "pandas.DataFrame":
output = pd.DataFrame({"starts": _starts, "widths": _widths, "ends": _ends})

if self._mcols is not None and self._mcols.shape[1] > 0:
output = pd.concat([output, self._mcols.to_pandas()])
output = pd.concat([output, self._mcols.to_pandas()], axis=1)

if self._names is not None:
output.index = self._names
Expand Down
8 changes: 8 additions & 0 deletions tests/test_IRanges_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ def test_pandas_export():
assert y is not None
assert isinstance(y, pd.DataFrame)
assert set(y.columns.tolist()).issubset(["starts", "ends", "widths"])

def test_pandas_with_mcols():
x = IRanges([1, 2, 3, 4], [4, 5, 6, 7], mcols=BiocFrame({"temp": ["a", "t", "g", "c"]}))

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

0 comments on commit aab666f

Please sign in to comment.