fix(get,pl): fix palette array categories and default depth_key#57
Conversation
Fix pycea.get.palette to collect unique categories across all columns of array data rather than only the first column. Default depth_key to None in pycea.pl.branches and pycea.pl.tree, resolving at call time to tdata.uns["default_depth"] if present, otherwise "depth". Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #57 +/- ##
==========================================
- Coverage 94.04% 93.98% -0.06%
==========================================
Files 35 35
Lines 3004 3008 +4
==========================================
+ Hits 2825 2827 +2
- Misses 179 181 +2
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fe8fe3dd47
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| all_values = pd.Series(data.values.ravel()) | ||
| categories = _get_categories(all_values, sort) | ||
| categorical_type = pd.CategoricalDtype(categories=categories, ordered=True) | ||
| data = data.apply(lambda col: col.astype(categorical_type)) |
There was a problem hiding this comment.
Preserve numeric array rejection in palette
When key points to a numeric obsm/obsp matrix, this unconditional cast converts every distinct number into a categorical level before the existing non-category check runs, so pycea.get.palette(tdata, "numeric_matrix") now returns a potentially huge discrete palette instead of rejecting continuous data like numeric obs/X keys still do. This affects common continuous matrices such as distances or expression embeddings and can produce misleading colors or excessive category generation; the array-wide category fix should only be applied when the array data is already categorical/object-like.
Useful? React with 👍 / 👎.
Only re-unify categories across array columns when the dtype is already CategoricalDtype. Numeric arrays (distances, embeddings) now fall through to the existing non-category check and raise ValueError as expected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
get_keyed_obs_data already ravels all columns and builds a unified CategoricalDtype (including already-categorical obsm data, since CategoricalDtype.kind == 'O'), so the extra unification in palette.py was redundant. Revert to key = data.columns[0]. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When cmap is None, _get_categorical_colors was called with the default subset=True, which filters the colormap to only values present in data[key].unique() — i.e. the first column only. This silently dropped categories that appear in other columns of array data even though get_keyed_obs_data had already unified them into the shared dtype. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
pycea.get.palette: Fixed a bug where array data (obsm/obspkeys) only collected categories from the first column. Now gathers unique values across all columns before building the sharedCategoricalDtype.pycea.pl.branches/pycea.pl.tree: Changeddepth_keydefault from"depth"toNone. At call time,Noneresolves totdata.uns["default_depth"]if that key exists, otherwise falls back to"depth".Test plan
tests/test_get_palette.pypasses (5 tests)tests/test_plot_tree.pypasses (12 tests)branches/treerespectstdata.uns["default_depth"]whendepth_keyis not set🤖 Generated with Claude Code