Skip to content

Commit 6d612ad

Browse files
authored
Fix coercion to pandas when IRanges contains mcols (#46)
Add tests and update changelog.
1 parent b6e6f2a commit 6d612ad

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ repos:
1717
- id: mixed-line-ending
1818
args: ['--fix=auto'] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows
1919

20-
- repo: https://github.com/PyCQA/docformatter
21-
rev: v1.7.5
22-
hooks:
23-
- id: docformatter
24-
additional_dependencies: [tomli]
25-
args: [--in-place, --wrap-descriptions=120, --wrap-summaries=120]
26-
# --config, ./pyproject.toml
20+
# - repo: https://github.com/PyCQA/docformatter
21+
# rev: v1.7.5
22+
# hooks:
23+
# - id: docformatter
24+
# additional_dependencies: [tomli]
25+
# args: [--in-place, --wrap-descriptions=120, --wrap-summaries=120]
26+
# # --config, ./pyproject.toml
2727

2828
- repo: https://github.com/psf/black
2929
rev: 24.8.0

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Changelog
22

3-
## Version 0.2.10
3+
## Version 0.2.10 - 0.2.12
44

55
- Added a numpy vectorized version of finding gaps (tldr: not fast compared to the traditional version). May be needs a better implementation
66
- Added NCLS based intersection operation (based on what pyranges does in their internals)
77
- Added tests for intersection operations.
8+
- Fixed and issue when coercing `IRanges` containing mcols.
89

910
## Version 0.2.8 - 0.2.9
1011

src/iranges/IRanges.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2220,7 +2220,7 @@ def to_pandas(self) -> "pandas.DataFrame":
22202220
output = pd.DataFrame({"starts": _starts, "widths": _widths, "ends": _ends})
22212221

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

22252225
if self._names is not None:
22262226
output.index = self._names

tests/test_IRanges_pandas.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,14 @@ def test_pandas_export():
2424
assert y is not None
2525
assert isinstance(y, pd.DataFrame)
2626
assert set(y.columns.tolist()).issubset(["starts", "ends", "widths"])
27+
28+
29+
def test_pandas_with_mcols():
30+
x = IRanges(
31+
[1, 2, 3, 4], [4, 5, 6, 7], mcols=BiocFrame({"temp": ["a", "t", "g", "c"]})
32+
)
33+
34+
y = x.to_pandas()
35+
assert y is not None
36+
assert isinstance(y, pd.DataFrame)
37+
assert set(y.columns.tolist()).issubset(["starts", "ends", "widths", "temp"])

0 commit comments

Comments
 (0)