Skip to content

Fix X_stats: 1-D columns for sparse X, and support dense X - #230

Open
Marius1311 wants to merge 1 commit into
lilab-bcb:mainfrom
quadbio:fix/x-stats-sparse-dense
Open

Fix X_stats: 1-D columns for sparse X, and support dense X#230
Marius1311 wants to merge 1 commit into
lilab-bcb:mainfrom
quadbio:fix/x-stats-sparse-dense

Conversation

@Marius1311

@Marius1311 Marius1311 commented Aug 18, 2026

Copy link
Copy Markdown

On sparse X, X.sum(axis=0) / X.mean(axis=0) return np.matrix, whose .flatten() stays 2-D, so X_stats raises ValueError: Data must be 1-dimensional and every request carrying stats 500s. Dense X fails 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

`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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant