Fix DistanceMatrix crash on read-only array from remove_zerors #199#200
Merged
Conversation
khasawn3
approved these changes
Jun 2, 2026
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
DistanceMatrixinteaspoon/TDA/PHN.pycallednp.fill_diagonal(A, 0)on the array returned bynetwork_tools.remove_zeros. That function returns its result via pandasto_numpy(), which is read-only on the numpy/pandas versions resolved for Python 3.11 and 3.12. Sincenp.fill_diagonalwrites in place, it raisedValueError: underlying array is read-only, which failed the CI test suite on 3.11 and 3.12 while 3.9 and 3.10 passed.The fix wraps the result in
np.array(...), which returns a writable copy regardless of the input's read-only flag. The diagonal is still zeroed exactly as before.Motivation and Context
Closes #199. The
Test Installsworkflow was red on Python 3.11 and 3.12 (all platforms), which blocked the checks on every pull request. This was pre-existing and not introduced by any recent.How has this been tested?
remove_zerosto return a read-only array, then confirmedDistanceMatrixraisedunderlying array is read-onlywithout the fix.test_point_summaries_empty_persistence_diagram, test_point_summaries_non_empty_persistence_diagram`) end-to-end under the same read-only condition — both pass, and no further read-only error appears downstream.tests/test_PointSummariesPHN.pynormally — 2 passed.Types of changes
Checklist
make clean)make html)pyproject.tomlfile.make tests)