Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Fix AttributeError: module 'pyranges' has no attribute 'from_dfs' #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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