Repository navigation
Honor falsey callable processors in cdist and cpdist - #505
Merged
Merged
Conversation
Member
|
Thanks for the contribution |
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.
Developed with AI assistance.
cdistandcpdistcan skip a callable processor when its__bool__returnsFalseor its__len__returns zero. For example, a falsey callable that lowercases its input gives a score of 0 for['A']against['a'], rather than 100. A callable that rejects truth-value testing also raises before preprocessing.Check processor identity rather than its truth value in the Python matrix functions and the Cython matrix preprocessing helpers. Preserve literal
Falseas a no-preprocessing sentinel in nativecdist/cpdistand Pythoncpdist. Pythoncdistpreviously raisedTypeErrorforprocessor=False; it now treats that sentinel consistently with the other matrix paths. The current documented API is callable orNone, but this patch keeps the accepted legacy behavior rather than removing it while fixing callables.Tests cover both backends, built-in and custom scorers, false
__bool__, zero__len__, a truth-value check that raises, and the symmetriccdistpath with a missing value. Compatibility controls coverNone, literalFalseand an ordinary callable.Local validation on Python 3.12:
cdist(False)behavior change. All 24 pass with this change.git diff --checkpass for the changed Python files.