Fix X_stats: 1-D columns for sparse X, and support dense X - #230
Open
Marius1311 wants to merge 1 commit into
Open
Fix X_stats: 1-D columns for sparse X, and support dense X#230Marius1311 wants to merge 1 commit into
Marius1311 wants to merge 1 commit into
Conversation
`X.sum(axis=0)` and `X.mean(axis=0)` on a scipy sparse matrix return `np.matrix`,
whose `.flatten()` yields a (1, n) matrix rather than a 1-D array, so building the
DataFrame raised:
ValueError: Data must be 1-dimensional, got ndarray of shape (1, 1)
This breaks every request that carries `stats`, i.e. the composition/summary views.
Dense `X` failed too, on the `.toarray()`/`.getnnz()` calls that only exist on
sparse matrices.
Reduce over each layout explicitly and use `np.asarray(...).ravel()`, which is 1-D
for both `np.matrix` and `ndarray`. Adds `tests/test_stats.py`, covering `X_stats`
and `FeatureAggregator` over sparse and dense inputs -- neither had any coverage,
which is how this survived.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X6uSHPpkfbneXYsprQ3wJ6
Marius1311
force-pushed
the
fix/x-stats-sparse-dense
branch
from
August 24, 2026 09:29
5b202b8 to
177828d
Compare
This was referenced Aug 24, 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.
On sparse
X,X.sum(axis=0)/X.mean(axis=0)returnnp.matrix, whose.flatten()stays 2-D, soX_statsraisesValueError: Data must be 1-dimensionaland every request carryingstats500s. DenseXfails too, on the sparse-only.toarray()/.getnnz()calls.Reduce over each layout explicitly and use
np.asarray(...).ravel().Adds
tests/test_stats.py— the function had no coverage. Rebased onto #234.🤖 Generated with Claude Code