Skip to content

Fix to_pandas() row-doubling when names is set and mcols has no matching row names - #165

Closed
mjsteinbaugh wants to merge 1 commit into
BiocPy:masterfrom
mjsteinbaugh:fix/to-pandas-mcols-index-order
Closed

Fix to_pandas() row-doubling when names is set and mcols has no matching row names#165
mjsteinbaugh wants to merge 1 commit into
BiocPy:masterfrom
mjsteinbaugh:fix/to-pandas-mcols-index-order

Conversation

@mjsteinbaugh

Copy link
Copy Markdown

Fixes #163.

to_pandas() set _rdf.index to self._names before concatenating self._mcols.to_pandas(), whose index was still the default positional RangeIndex. pandas.concat(axis=1) then outer-joined on the two disjoint indices instead of binding columns positionally, doubling the row count and NaN-splitting every row.

This moves the index assignment to after the mcols concat, matching IRanges.to_pandas() in the sibling iranges package, which already does it in this order and is unaffected.

Added a regression test (test_to_pandas_with_names_and_mcols_is_positional) using the exact repro from the issue. Ran the full existing test suite locally against the patched source: 100 passed, 1 unrelated skip, no new failures (tests/test_gr_initialize_polars.py excluded, polars not available in my environment, unrelated to this change).

@jkanche

jkanche commented Aug 21, 2026

Copy link
Copy Markdown
Member

Thank you for the PR. I already started working on this in #164, which also fixes a polars related issue. I would close this since the changes here are already fixed in the other PR.

@jkanche jkanche closed this Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GenomicRanges.to_pandas() silently doubles the row count when names is set and mcols has no matching row names

2 participants