Skip to content

fix: replace U100/U1000 dtypes with object in DataFrame exports - #8606

Closed
aryab08 wants to merge 1 commit into
OpenMS:developfrom
aryab08:fix-dataframe-column-types
Closed

aryab08 wants to merge 1 commit into
OpenMS:developfrom
aryab08:fix-dataframe-column-types

Conversation

@aryab08

@aryab08 aryab08 commented Jan 6, 2026 •

Copy link
Copy Markdown

Fixes #8583

Changes Made

  • Replaced fixed-width Unicode dtypes (U100, U200, U1000) with object dtype
  • Updated PeptideIdentificationList, MRMTransitionGroupCP, FeatureMap, MSChromatogram, MSSpectrum, and ConsensusMap

Rationale

  • object dtype uses Python string objects for memory efficiency and safety
  • avoids unnecessary large allocations like U1000
  • consistent with other dataframe exports

Summary by CodeRabbit

  • Refactor
    • Improved internal data type handling across multiple modules for more flexible storage of metadata fields and identifiers, enhancing compatibility and performance of data export operations.

✏️ Tip: You can customize this high-level summary in your review settings.

- Replaced fixed-width Unicode dtypes (U100, U200, U1000) with object dtype
- Updated PeptideIdentificationList, MRMTransitionGroupCP, FeatureMap, MSChromatogram, MSSpectrum, and ConsensusMap
- Object dtype uses Python string objects for memory efficiency and safety

Closes OpenMS#8583
@coderabbitai

coderabbitai Bot commented Jan 6, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The PR changes dtype specifications across six pyOpenMS addon files, replacing fixed-size Unicode string types ('U100', 'U200') with Python object dtype for string columns in DataFrame exports. This addresses memory inefficiency by using flexible object storage instead of pre-allocated fixed-width Unicode arrays.

Changes

Cohort / File(s) Summary
String dtype conversion in metadata exports
src/pyOpenMS/addons/ConsensusMap.pyx, src/pyOpenMS/addons/FeatureMap.pyx, src/pyOpenMS/addons/MRMTransitionGroupCP.pyx, src/pyOpenMS/addons/MSChromatogram.pyx, src/pyOpenMS/addons/MSSpectrum.pyx, src/pyOpenMS/addons/PeptideIdentificationList.pyx
Changed string column dtype specifications from fixed-width Unicode ('U100', 'U200') to Python object ('object') in DataFrame construction methods. Affects spectrum_native_id, PeptideRef, feature_id, peptide_sequence, sequence, native_id, chromatogram_type, comment, ID_filename, and ID_native_id fields. No control-flow or API signature changes; dtype handling becomes more memory-efficient and flexible for variable-length strings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • timosachsenberg

Poem

🐰 Strings once fixed in rigid bounds,
Now dance freely, memory rebounds!
Objects flex where Unicode strained,
Cache and heap both entertained.
Efficient whiskers approve this change! ✨

Pre-merge checks

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: replacing fixed-width Unicode dtypes (U100/U1000) with object dtype across DataFrame exports.
Linked Issues check ✅ Passed The PR directly addresses issue #8583 by replacing fixed-width Unicode dtypes (U100, U200, U1000) with object dtype across six affected modules, meeting the primary requirement to optimize memory usage.
Out of Scope Changes check ✅ Passed All changes are focused on replacing dtype specifications in DataFrame exports across six modules, directly aligned with the issue's scope. No unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9c6d28e and 2cc8cc8.

📒 Files selected for processing (6)
  • src/pyOpenMS/addons/ConsensusMap.pyx
  • src/pyOpenMS/addons/FeatureMap.pyx
  • src/pyOpenMS/addons/MRMTransitionGroupCP.pyx
  • src/pyOpenMS/addons/MSChromatogram.pyx
  • src/pyOpenMS/addons/MSSpectrum.pyx
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{py,pyx,pxd}

📄 CodeRabbit inference engine (AGENTS.md)

Use 4-space indentation in Python and Cython files per PEP 8, not tabs

Files:

  • src/pyOpenMS/addons/MRMTransitionGroupCP.pyx
  • src/pyOpenMS/addons/MSChromatogram.pyx
  • src/pyOpenMS/addons/ConsensusMap.pyx
  • src/pyOpenMS/addons/FeatureMap.pyx
  • src/pyOpenMS/addons/MSSpectrum.pyx
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
**/*.{h,hpp,hxx,cpp,cc,cxx,py,pyx,pxd,cmake}

📄 CodeRabbit inference engine (AGENTS.md)

Use Unix line endings (LF) in all code files

Files:

  • src/pyOpenMS/addons/MRMTransitionGroupCP.pyx
  • src/pyOpenMS/addons/MSChromatogram.pyx
  • src/pyOpenMS/addons/ConsensusMap.pyx
  • src/pyOpenMS/addons/FeatureMap.pyx
  • src/pyOpenMS/addons/MSSpectrum.pyx
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
**/*.{h,hpp,hxx,cpp,cc,cxx,py,pyx}

📄 CodeRabbit inference engine (AGENTS.md)

Write code comments in plain English describing the next few lines of code, comprising at least ~5% of code

Files:

  • src/pyOpenMS/addons/MRMTransitionGroupCP.pyx
  • src/pyOpenMS/addons/MSChromatogram.pyx
  • src/pyOpenMS/addons/ConsensusMap.pyx
  • src/pyOpenMS/addons/FeatureMap.pyx
  • src/pyOpenMS/addons/MSSpectrum.pyx
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
src/pyOpenMS/**/*.{py,pyx,pxd}

📄 CodeRabbit inference engine (AGENTS.md)

Use snake_case for Python-facing names and DataFrame column names in pyOpenMS

Files:

  • src/pyOpenMS/addons/MRMTransitionGroupCP.pyx
  • src/pyOpenMS/addons/MSChromatogram.pyx
  • src/pyOpenMS/addons/ConsensusMap.pyx
  • src/pyOpenMS/addons/FeatureMap.pyx
  • src/pyOpenMS/addons/MSSpectrum.pyx
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
src/pyOpenMS/**/*.{pyx,pxd}

📄 CodeRabbit inference engine (AGENTS.md)

Avoid custom __init__ in pyOpenMS unless required; it overrides autowrap dispatchers

Files:

  • src/pyOpenMS/addons/MRMTransitionGroupCP.pyx
  • src/pyOpenMS/addons/MSChromatogram.pyx
  • src/pyOpenMS/addons/ConsensusMap.pyx
  • src/pyOpenMS/addons/FeatureMap.pyx
  • src/pyOpenMS/addons/MSSpectrum.pyx
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
src/pyOpenMS/addons/*.pyx

📄 CodeRabbit inference engine (AGENTS.md)

src/pyOpenMS/addons/*.pyx: Implement get_data_dict() in pyOpenMS addon to return numpy arrays
Keep pyOpenMS addon code minimal; avoid redundant aliases and over-engineering

Files:

  • src/pyOpenMS/addons/MRMTransitionGroupCP.pyx
  • src/pyOpenMS/addons/MSChromatogram.pyx
  • src/pyOpenMS/addons/ConsensusMap.pyx
  • src/pyOpenMS/addons/FeatureMap.pyx
  • src/pyOpenMS/addons/MSSpectrum.pyx
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
src/pyOpenMS/**/*.{py,pyx}

📄 CodeRabbit inference engine (AGENTS.md)

Do not call .decode() on autowrap string returns in pyOpenMS; autowrap returns Python strings

Files:

  • src/pyOpenMS/addons/MRMTransitionGroupCP.pyx
  • src/pyOpenMS/addons/MSChromatogram.pyx
  • src/pyOpenMS/addons/ConsensusMap.pyx
  • src/pyOpenMS/addons/FeatureMap.pyx
  • src/pyOpenMS/addons/MSSpectrum.pyx
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
src/pyOpenMS/**/*.pyx

📄 CodeRabbit inference engine (AGENTS.md)

src/pyOpenMS/**/*.pyx: Avoid cdef for autowrap string returns in pyOpenMS Cython code
Avoid cdef typed variables for autowrap return values inside def methods in pyOpenMS
Use strict indentation for # wrap-doc: comments in pyOpenMS Cython code

Files:

  • src/pyOpenMS/addons/MRMTransitionGroupCP.pyx
  • src/pyOpenMS/addons/MSChromatogram.pyx
  • src/pyOpenMS/addons/ConsensusMap.pyx
  • src/pyOpenMS/addons/FeatureMap.pyx
  • src/pyOpenMS/addons/MSSpectrum.pyx
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
🧠 Learnings (13)
📓 Common learnings
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Applies to src/pyOpenMS/**/*.{py,pyx,pxd} : Use snake_case for Python-facing names and DataFrame column names in pyOpenMS
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Applies to src/pyOpenMS/pxds/*.pxd : Do not add Python-only methods to pyOpenMS `.pxd` files; use addons or `_dataframes.py` wrappers
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Applies to src/pyOpenMS/**/*.pyx : Avoid `cdef` for autowrap string returns in pyOpenMS Cython code
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Applies to src/pyOpenMS/addons/*.pyx : Implement `get_data_dict()` in pyOpenMS addon to return numpy arrays
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Update pyOpenMS bindings when making C++ API changes
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Applies to src/pyOpenMS/**/*.{py,pyx} : Do not call `.decode()` on autowrap string returns in pyOpenMS; autowrap returns Python strings
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Applies to src/pyOpenMS/**/*.pyx : Avoid `cdef` typed variables for autowrap return values inside `def` methods in pyOpenMS
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Applies to src/pyOpenMS/pxds/*.pxd : Keep `.pxd` file signatures in sync with C++ APIs; update or remove `wrap-ignore` when wrapping changes
📚 Learning: 2026-01-05T17:45:38.981Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Update pyOpenMS bindings when making C++ API changes

Applied to files:

  • src/pyOpenMS/addons/MRMTransitionGroupCP.pyx
  • src/pyOpenMS/addons/MSChromatogram.pyx
  • src/pyOpenMS/addons/ConsensusMap.pyx
  • src/pyOpenMS/addons/MSSpectrum.pyx
📚 Learning: 2026-01-05T17:45:38.981Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Applies to src/pyOpenMS/pxds/*.pxd : Keep `.pxd` file signatures in sync with C++ APIs; update or remove `wrap-ignore` when wrapping changes

Applied to files:

  • src/pyOpenMS/addons/MRMTransitionGroupCP.pyx
  • src/pyOpenMS/addons/MSChromatogram.pyx
  • src/pyOpenMS/addons/ConsensusMap.pyx
  • src/pyOpenMS/addons/FeatureMap.pyx
  • src/pyOpenMS/addons/MSSpectrum.pyx
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
📚 Learning: 2026-01-05T17:45:38.981Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Applies to src/pyOpenMS/pxds/*.pxd : Do not add Python-only methods to pyOpenMS `.pxd` files; use addons or `_dataframes.py` wrappers

Applied to files:

  • src/pyOpenMS/addons/MRMTransitionGroupCP.pyx
  • src/pyOpenMS/addons/MSChromatogram.pyx
  • src/pyOpenMS/addons/ConsensusMap.pyx
  • src/pyOpenMS/addons/FeatureMap.pyx
  • src/pyOpenMS/addons/MSSpectrum.pyx
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
📚 Learning: 2026-01-05T17:45:38.981Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Applies to src/pyOpenMS/**/*.pyx : Avoid `cdef` typed variables for autowrap return values inside `def` methods in pyOpenMS

Applied to files:

  • src/pyOpenMS/addons/MRMTransitionGroupCP.pyx
  • src/pyOpenMS/addons/MSChromatogram.pyx
📚 Learning: 2025-08-05T12:43:11.681Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-05T12:43:11.681Z
Learning: Applies to src/pyOpenMS/**/*.h : Add Doxygen comments for new public methods and classes in pyOpenMS bindings

Applied to files:

  • src/pyOpenMS/addons/MSChromatogram.pyx
📚 Learning: 2026-01-05T17:45:38.981Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Applies to src/pyOpenMS/**/*.{py,pyx,pxd} : Use snake_case for Python-facing names and DataFrame column names in pyOpenMS

Applied to files:

  • src/pyOpenMS/addons/MSChromatogram.pyx
  • src/pyOpenMS/addons/MSSpectrum.pyx
  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
📚 Learning: 2026-01-05T17:45:38.981Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Applies to src/pyOpenMS/addons/*.pyx : Keep pyOpenMS addon code minimal; avoid redundant aliases and over-engineering

Applied to files:

  • src/pyOpenMS/addons/MSChromatogram.pyx
📚 Learning: 2026-01-05T17:45:38.981Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Applies to src/pyOpenMS/**/*.pyx : Avoid `cdef` for autowrap string returns in pyOpenMS Cython code

Applied to files:

  • src/pyOpenMS/addons/MSChromatogram.pyx
📚 Learning: 2026-01-05T17:45:38.981Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Applies to src/pyOpenMS/addons/*.pyx : Implement `get_data_dict()` in pyOpenMS addon to return numpy arrays

Applied to files:

  • src/pyOpenMS/addons/MSChromatogram.pyx
  • src/pyOpenMS/addons/MSSpectrum.pyx
📚 Learning: 2026-01-05T17:45:38.981Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Applies to src/pyOpenMS/**/*.{py,pyx} : Do not call `.decode()` on autowrap string returns in pyOpenMS; autowrap returns Python strings

Applied to files:

  • src/pyOpenMS/addons/MSChromatogram.pyx
📚 Learning: 2025-04-07T21:15:07.674Z
Learnt from: jpfeuffer
Repo: OpenMS/OpenMS PR: 7970
File: src/pyOpenMS/addons/MSSpectrum.pyx:38-38
Timestamp: 2025-04-07T21:15:07.674Z
Learning: In mass spectrometry data, precursor charges can be negative, so signed integer types (like np.int16) should be used instead of unsigned integers (like np.uint16) when storing charge values.

Applied to files:

  • src/pyOpenMS/addons/FeatureMap.pyx
📚 Learning: 2026-01-05T17:45:38.981Z
Learnt from: CR
Repo: OpenMS/OpenMS PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-05T17:45:38.981Z
Learning: Applies to src/pyOpenMS/pyopenms/_dataframes.py : Wrap DataFrame functionality with `get_df()` in `src/pyOpenMS/pyopenms/_dataframes.py`

Applied to files:

  • src/pyOpenMS/addons/PeptideIdentificationList.pyx
🔇 Additional comments (8)
src/pyOpenMS/addons/MSSpectrum.pyx (1)

166-166: LGTM! Memory-efficient dtype for native_id.

The change from fixed-width Unicode ('U100') to object dtype for the native_id field is appropriate and improves memory efficiency by storing Python string objects instead of pre-allocated 400-byte buffers per entry.

src/pyOpenMS/addons/MRMTransitionGroupCP.pyx (1)

137-137: LGTM! Improved dtype mappings for meta values.

The changes from 'U100' to 'object' dtype for spectrum_native_id and PeptideRef are appropriate. This avoids wasteful 400-byte allocations per entry and allows flexible storage of variable-length identifiers.

Also applies to: 146-146

src/pyOpenMS/addons/ConsensusMap.pyx (1)

335-335: LGTM! More efficient sequence storage.

The change from 'U200' to 'object' dtype for the sequence field eliminates wasteful 800-byte pre-allocations and allows efficient storage of variable-length peptide sequences.

src/pyOpenMS/addons/MSChromatogram.pyx (1)

137-137: LGTM! Efficient dtype choices for chromatogram metadata.

The changes from 'U100' to 'object' dtype for native_id, chromatogram_type, and comment fields are appropriate. This eliminates unnecessary 400-byte allocations per entry and uses flexible Python string storage instead.

Also applies to: 155-155, 158-158

src/pyOpenMS/addons/FeatureMap.pyx (2)

199-199: LGTM! Better dtype mappings for meta values.

The changes from 'U100' to 'object' dtype for spectrum_native_id and PeptideRef in the common_meta_value_types mapping are appropriate and improve memory efficiency by avoiding fixed 400-byte allocations.

Also applies to: 208-208


277-277: LGTM! Memory-efficient dtypes for feature identifiers.

The changes from 'U100' to 'object' dtype for feature_id, peptide_sequence, ID_filename, and ID_native_id are correct. This eliminates wasteful fixed-width allocations and uses flexible Python string objects for variable-length identifiers.

Also applies to: 279-279

src/pyOpenMS/addons/PeptideIdentificationList.pyx (2)

129-129: LGTM: String dtype mapping updated to object.

The change from 'U100' to 'object' for string-type metavalues aligns with the PR objectives to use memory-efficient object dtype instead of fixed-width Unicode allocations.


179-179: No action required.

The 'id' column correctly uses object dtype to store bytes from pep.getIdentifier().encode('utf-8'). This is intentional behavior, not a problem. The previous 'U100' dtype would have forced unwanted conversion of bytes to Unicode strings. The change to 'object' properly preserves the bytes representation consistent with OpenMS conventions (e.g., lprot.id == b"1234").

Tests do not expose the 'id' column downstream; merge operations use alternative column names ('feature_id', 'ID_native_id', 'ID_filename'). No compatibility issues exist.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@timosachsenberg

Copy link
Copy Markdown
Contributor

why another PR with name fix: replace U100/U1000 dtypes with object in DataFrame exports?

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.

Revisit dataframe export column types

2 participants