Skip to content

Commit

Permalink
Fix coercion to pandas when IRanges contains mcols (#46)
Browse files Browse the repository at this point in the history
Add tests and update changelog.
  • Loading branch information
jkanche authored Oct 15, 2024
1 parent b6e6f2a commit 6d612ad
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ repos:
- id: mixed-line-ending
args: ['--fix=auto'] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows

- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
hooks:
- id: docformatter
additional_dependencies: [tomli]
args: [--in-place, --wrap-descriptions=120, --wrap-summaries=120]
# --config, ./pyproject.toml
# - repo: https://github.com/PyCQA/docformatter
# rev: v1.7.5
# hooks:
# - id: docformatter
# additional_dependencies: [tomli]
# args: [--in-place, --wrap-descriptions=120, --wrap-summaries=120]
# # --config, ./pyproject.toml

- repo: https://github.com/psf/black
rev: 24.8.0
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Changelog

## Version 0.2.10
## Version 0.2.10 - 0.2.12

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

## Version 0.2.8 - 0.2.9

Expand Down
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
11 changes: 11 additions & 0 deletions tests/test_IRanges_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,14 @@ 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 6d612ad

Please sign in to comment.