Skip to content

Rows duplication with join_overlaps #154

Description

@Picani

Hi

First, thanks a lot for that incredible lib!

I encounter a bug while using join_overlaps in left-join fashion. When using an index in the left pandas DataFrame, if the index doesn't start at 0, one row is duplicated.

Examples

Without index

left = pd.DataFrame([
    {"Chromosome": "1", "Start": 100, "End": 200},
    {"Chromosome": "2", "Start": 300, "End": 400},
    
])

right = pd.DataFrame([
    {"Chromosome": "1", "Start": 150, "End": 160},
])

print(pr.PyRanges(left).join_overlaps(pr.PyRanges(right), join_type="left"))

Which prints as expected

index  |      Chromosome    Start      End    Start_b      End_b
int64  |             str    int64    int64    float64    float64
-------  ---  ------------  -------  -------  ---------  ---------
    0  |               1      100      200        150        160
    1  |               2      300      400        nan        nan
PyRanges with 2 rows, 5 columns, and 1 index columns.
Contains 2 chromosomes.

With an index starting at zero

left = pd.DataFrame([
    {"Chromosome": "1", "Start": 100, "End": 200},
    {"Chromosome": "2", "Start": 300, "End": 400},
], index=[0, 1])

right = pd.DataFrame([
    {"Chromosome": "1", "Start": 150, "End": 160},
])

print(pr.PyRanges(left).join_overlaps(pr.PyRanges(right), join_type="left"))

Which prints as expected

index  |      Chromosome    Start      End    Start_b      End_b
int64  |             str    int64    int64    float64    float64
-------  ---  ------------  -------  -------  ---------  ---------
    0  |               1      100      200        150        160
    1  |               2      300      400        nan        nan
PyRanges with 2 rows, 5 columns, and 1 index columns.
Contains 2 chromosomes.

Note that with [1, 0] as index, it works well too.

With an index starting at 1

left = pd.DataFrame([
    {"Chromosome": "1", "Start": 100, "End": 200},
    {"Chromosome": "2", "Start": 300, "End": 400},
], index=[1, 2])

right = pd.DataFrame([
    {"Chromosome": "1", "Start": 150, "End": 160},
])

print(pr.PyRanges(left).join_overlaps(pr.PyRanges(right), join_type="left"))

Which prints

index  |      Chromosome    Start      End    Start_b      End_b
int64  |             str    int64    int64    float64    float64
-------  ---  ------------  -------  -------  ---------  ---------
    0  |               1      100      200        150        160
    1  |               1      100      200        nan        nan
    2  |               2      300      400        nan        nan
PyRanges with 3 rows, 5 columns, and 1 index columns.
Contains 2 chromosomes.

Note that with [2, 1] as index, it gives the same wrong result.

Environment

  • Python v3.12.10
  • pandas v3.0.3
  • pyranges1 v1.3.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions