Skip to content

Commit

Permalink
- Fix AttributeError: module 'pyranges' has no attribute 'from_dfs'
Browse files Browse the repository at this point in the history
… causing to_ranges function to return a pandas Dataframe instead of PyRanges object (pyranges#9)

- Logging exception in case the to_ranges function fails at creating the pr.PyRanges object
- adding Exception (PEP 8: E722)
  • Loading branch information
Isy89 committed Apr 7, 2024
1 parent b8f66dd commit 6276cd0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.0.38 (08.04.2024) (@Isy89)
- Fix `AttributeError: module 'pyranges' has no attribute 'from_dfs'` causing to_ranges function to return a pandas
Dataframe instead of PyRanges object (#9)

# 0.0.37 (18.05.23)
- remove option to return 32-bit PyRanges

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pyrle"
version = "0.0.39"
version = "0.0.40"
description = "Numeric run length encoding for Python."
readme = "README.md"
authors = [{ name = "Endre Bakken Stovner", email = "[email protected]" }]
Expand Down
11 changes: 8 additions & 3 deletions pyrle/methods.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os
from collections import defaultdict

Expand All @@ -9,6 +10,8 @@
from pyrle import rledict as rd # type: ignore
from pyrle.src.coverage import _coverage # type: ignore

logger = logging.getLogger(__name__)


class suppress_stdout_stderr(object):
"""
Expand Down Expand Up @@ -179,14 +182,15 @@ def to_ranges_df_no_strand(rle, k):


def to_ranges(grles, nb_cpu=1):
import pyranges as pr# type: ignore
import pyranges as pr # type: ignore

func = to_ranges_df_strand if grles.stranded else to_ranges_df_no_strand

func.remote = func

def get(x):
return x

dfs, keys = [], []
for k, v in grles.items():
result = func.remote(v, k)
Expand All @@ -196,8 +200,9 @@ def get(x):
dfs = {k: v for (k, v) in zip(keys, get(dfs))}

try:
return pr.from_dfs(dfs)
except:
return pr.PyRanges(dfs)
except Exception:
logger.exception("It was not possible to return a PyRanges object. Returning a pandas Dataframe.")
return pd.concat(dfs.values())


Expand Down

0 comments on commit 6276cd0

Please sign in to comment.