Skip to content

export matrix: pandas IndexError in _summarize_peptide_level (v3.0.7) #193

@timosachsenberg

Description

@timosachsenberg

Description

pyprophet export matrix crashes with a pandas IndexError in _summarize_peptide_level (file pyprophet/io/_base.py, line ~804). This affects both --level=peptide and --level=protein exports.

Environment

  • pyprophet 3.0.7
  • pandas 2.1.4 (also reproducible with 2.3.3)
  • Python 3.10.19
  • Linux

Error

File "pyprophet/io/_base.py", line 804, in _summarize_peptide_level
    data = data.iloc[
        data.groupby(["run_id", "transition_group_id"]).apply(
            lambda x: x["m_score"].idxmin()
        )
    ]
IndexError: DataFrame indexer is not allowed for .iloc
Consider using .loc for automatic alignment.

Root cause

groupby().apply() returns a Series object. In recent pandas versions (>=2.1), passing a Series to .iloc[] is no longer allowed. The fix is to use .loc[] with idxmin() directly:

# Before (broken):
data = data.iloc[
    data.groupby(["run_id", "transition_group_id"]).apply(
        lambda x: x["m_score"].idxmin()
    )
]

# After (fixed):
idx = data.groupby(["run_id", "transition_group_id"])["m_score"].idxmin()
data = data.loc[idx]

Note: there is a second instance of the same .iloc pattern in the same function (for _summarize_protein_level) that should be fixed as well.

Steps to reproduce

  1. Run pyprophet score on an .osw file
  2. Run pyprophet export matrix --level=peptide

The crash occurs in _summarize_peptide_level regardless of the data content.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
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