Return NaN instead of crashing when every EMD stratum is too small - #131
Merged
Conversation
* Guard the pd.concat() calls in both the horizontal and vertical path * Warn as soon as one cell type is missing from a split, not two * Fix the newline in that warning
Contributor
|
Not fixing the |
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.
Describe your changes
Both EMD paths skip a stratum when either side has fewer than 50 cells, and both then call
pd.concat()on the collected results. If every stratum is skipped, that list is empty andpd.concat()raisesValueError: No objects to concatenate, so the whole metric component dies instead of reporting that it couldn't be computed.The vertical path already handles the neighbouring case gracefully -- if there aren't at least 2 samples per group it returns
np.nan-- so this PR extends the same treatment to the empty-results case in both paths:get_vert_emd_for_integrated_adata()returnsnp.nanwhen no sample combination and cell type had enough cells.calculate_horizontal_emd()returnsnp.nanfor both its keys when no donor and cell type had enough cells.Also two small things in the same block:
len(cell_type_not_in_both) > 1, so it stayed quiet in the most common case of exactly one missing cell type. Changed to> 0.]nrather than a newline, and joined the cell type names without a separator.Note that with
errorStrategyset toignoreafter retries, a crash here currently looks the same as a missing score in the output -- which is part of why it is worth turning into an explicit NaN.Found while reviewing the task ahead of the next full benchmark run -- see also the sibling PRs.
Checklist before requesting a review
I have performed a self-review of my code
Check the correct box. Does this PR contain:
Proposed changes are described in the CHANGELOG.md
CI Tests succeed and look good!