Repository navigation
fix(machine_learning): call features.any() in linear_discriminant_analysis - #15606
Open
hardikkaurani wants to merge 1 commit into
Open
hardikkaurani wants to merge 1 commit into
hardikkaurani wants to merge 1 commit into
Conversation
…lysis In linear_discriminant_analysis, line 146 wrote if features.any: instead of calling if features.any():. Because the method object is always truthy, the else branch handling empty datasets was unreachable dead code, triggering ty warning[redundant-condition]. Call eatures.any() (matching line 107 in principal_component_analysis) and add a test case in test_linear_discriminant_analysis verifying that an empty dataset properly enters the else branch. Validation: - uvx ty check machine_learning/dimensionality_reduction.py -> All checks passed (0 diagnostics) - uvx --with scipy --with scikit-learn --with numpy pytest machine_learning/dimensionality_reduction.py --doctest-modules -> 9 passed - uvx ruff check / format -> clean
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
Author
|
Hi @cclauss, I've opened this PR to resolve an uncalled method in Overview:
Validation:
Whenever you have a moment, could you please take a look? Thank you! |
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.
Describe your change
Problem & Context
In
machine_learning/dimensionality_reduction.py, line 146 inlinear_discriminant_analysiswrote:instead of calling the method
if features.any():(compare with line 107 inprincipal_component_analysis, which correctly usesif features.any():).Because an
ndarray.anybound method object is always truthy,ty checkemitted:As a result, the
elsebranch handling empty datasets was unreachable dead code, and passing an empty dataset would bypass the check and fail with an unexpected error insidecovariance_between_classes.Fix
features.any()inlinear_discriminant_analysis, matchingprincipal_component_analysis.test_linear_discriminant_analysisverifying that an empty dataset raisesAssertionError.Validation
uvx ty check machine_learning/dimensionality_reduction.py-> All checks passed (0 diagnostics).uvx --with scipy --with scikit-learn --with numpy pytest machine_learning/dimensionality_reduction.py --doctest-modules-> 9 passed.uvx ruff check machine_learning/dimensionality_reduction.py-> All checks passed.uvx ruff format --check machine_learning/dimensionality_reduction.py-> 1 file already formatted.Checklist