Fix add_peak_annotation crash on empty distance values#182
Open
LiudengZhang wants to merge 2 commits intoscverse:mainfrom
Open
Fix add_peak_annotation crash on empty distance values#182LiudengZhang wants to merge 2 commits intoscverse:mainfrom
LiudengZhang wants to merge 2 commits intoscverse:mainfrom
Conversation
When the distance column in peak annotation TSV contains empty values (intergenic peaks), pandas may infer a numeric dtype. This caused LossySetitemError when trying to assign "" into the numeric column. Fix by converting distance to string via object dtype early, and using pd.to_numeric with errors="coerce" for the final int conversion, which gracefully handles empty/NaN values as 0. Add regression tests for empty distance values and semicolon-separated multi-gene annotations. Closes scverse#181
Collaborator
|
Thank you for the fix! I've pushed a slight update to your branch: Given how long ago Pandas 1.0 was released, we can assume that people using a somewhat up to date muon have it, and get rid of all this string casting nonsense and just use |
Author
|
Thanks for the cleanup — the |
Author
|
Thanks for the cleanup! Feel free to merge. |
Pandas 1.0 has been released sufficiently long ago that we can assume muon users have it.
8d28154 to
eca6756
Compare
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.
Description
Fix
add_peak_annotationcrashing when the peak annotation TSV contains empty distance values (intergenic peaks).Root cause: When the distance column contains a mix of numeric values and empty strings,
pd.read_csvinfers it asfloat64. The existing code then tries to assign""into a numeric column, triggeringLossySetitemError. On newer pandas withStringDtype, a similar issue occurs withpd.NAvalues.Fix:
astype(object).fillna("").astype(str)to safely handle both numeric and nullable string dtypes""→0→float→intconversion withpd.to_numeric(errors="coerce").fillna(0).astype(int), which handles all edge cases in one expressionHow has this been tested?
pytest tests/— 13 passed)Closes
Closes #181