Repository navigation
Conversation
…NaN metadata Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LKxc9GKLwnyeV2jaZBxH9N
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Who hits this: Anyone importing DIA-NN
.parquetor Spectronaut/OpenSWATH TSV spectral libraries withLibraryReaderBasewhere any non-fragment metadata column (such asGenes,Protein.Names, orIonMobility/IM) has missing values for a subset of precursors (for example contaminant entriesCON__*, unannotated UniProt entries, or non-TIMS precursors). #418Root cause
In
alphabase/spectral_library/reader.py:LibraryReaderBase._get_fragment_intensity():lib_df.dropna(axis=1, how="all")drops only completely empty columns, leaving partially populated metadata columns innon_fragment_columns.PSMReaderBase._load_file()(which calls_sanitize_missing_values()),LibraryReaderBase._load_file()leavesNone/NaNin partially missing string columns (from Parquet orNA/NaNtokens in TSV).lib_df.groupby(non_fragment_columns)uses pandas' defaultdropna=True, which silently discards every precursor whose grouping key containsNoneorNaNin any non-fragment column. If every precursor has a missing value in at least one partially populated metadata column,groupbyyields zero groups andnp.concatenate(frag_intens_list)raisesValueError: need at least one array to concatenate.alphabase/utils.py:_sanitize_missing_values()calleddf[column].fillna("")on string-likeCategoricalcolumns (for whichpd.api.types.is_string_dtypereturnsTrue), which raisesTypeError: Cannot setitem on a Categorical with a new category ()whenever""is not already incat.categories.Changes
alphabase/spectral_library/reader.py:_sanitize_missing_values(lib_df)immediately afterlib_df.dropna(axis=1, how="all")(preserving existing removal of 100%-empty optional columns).dropna=False, observed=Truetolib_df.groupby(non_fragment_columns, ...)so precursors with partially missing numeric metadata (e.g.IM=NaN, whichmobility_to_ccs_for_df()maps toccs=0.0) are preserved withoutFutureWarningon pandas 2.x.alphabase/utils.py:pd.CategoricalDtypecolumns in_sanitize_missing_values(): for string categoricals containing nulls, add""to categories beforefillna(""); leave non-null string categoricals and numeric categoricals untouched.tests/unit/spectral_library/test_reader.py&tests/unit/test_utils.py:None/NaNin Parquet, partialNA/NaNin TSV, all-precursors-partial-nulls (noValueError), 100%-NaN optional columns still dropped, complete and partially missingCategoricalGenescolumns, and_sanitize_missing_valuescategorical handling.Verification
pandas 2.2.3andpandas 3.1.1:PEPTIDEKwithGenes=None/NA,MELODYRwithIM=NaN): baseline silently dropped 2 of 3 precursors (1precursor /7dense fragment rows); patched keeps all3precursors /20dense fragment rows withgenes == ""forPEPTIDEK,ccs == 0.0forMELODYR, and theoretical fragment m/z values matchingalphabase.constantsto< 1e-4 Da.ValueError: need at least one array to concatenate; patched returns both precursors and13dense fragment rows.diann_speclib_head.parquetwithGenesre-encoded ascategory: imports all21precursors /375dense rows with exact parity to stringGenesand zeroTypeError/FutureWarning.SpecLibBase(mobility_to_ccs_for_df,calc_precursor_mz,refine_df,save_hdf/load_hdf) verified onpandas 2.2.3.pandas 2.2.3:pytest tests/unit314 passed;pytest tests/integration/test_psm_readers.py21 passed (includingtest_diann_speclib_readerandtest_diann_parquet_speclib_reader).pandas 3.1.1:pytest tests/unit314 passed.ruff check,ruff format --check, and scopedruff --config ruff-lint-psm-readers.tomlall pass with 0 errors.Found and written with AI agents; a separate AI referee reproduced the problem before this PR.
🤖 Generated with Claude Code
https://claude.ai/code/session_01LKxc9GKLwnyeV2jaZBxH9N