Skip to content

fix(get,pl): fix palette array categories and default depth_key#57

Merged
colganwi merged 4 commits into
mainfrom
fix/palette-array-categories-and-depth-key-default
May 28, 2026
Merged

fix(get,pl): fix palette array categories and default depth_key#57
colganwi merged 4 commits into
mainfrom
fix/palette-array-categories-and-depth-key-default

Conversation

@colganwi

Copy link
Copy Markdown
Collaborator

Summary

  • pycea.get.palette: Fixed a bug where array data (obsm/obsp keys) only collected categories from the first column. Now gathers unique values across all columns before building the shared CategoricalDtype.
  • pycea.pl.branches / pycea.pl.tree: Changed depth_key default from "depth" to None. At call time, None resolves to tdata.uns["default_depth"] if that key exists, otherwise falls back to "depth".

Test plan

  • Existing tests/test_get_palette.py passes (5 tests)
  • Existing tests/test_plot_tree.py passes (12 tests)
  • Verify palette with array data where values only appear in non-first columns are included
  • Verify branches/tree respects tdata.uns["default_depth"] when depth_key is not set

🤖 Generated with Claude Code

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

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.98%. Comparing base (619c770) to head (4e66651).

Files with missing lines Patch % Lines
src/pycea/pl/plot_tree.py 50.00% 2 Missing ⚠️
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     
Files with missing lines Coverage Δ
src/pycea/get/palette.py 91.80% <100.00%> (ø)
src/pycea/pl/plot_tree.py 94.56% <50.00%> (-0.58%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/pycea/get/palette.py Outdated
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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

colganwi and others added 3 commits May 27, 2026 18:00
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>
@colganwi colganwi merged commit d807c24 into main May 28, 2026
7 of 8 checks passed
@colganwi colganwi deleted the fix/palette-array-categories-and-depth-key-default branch May 28, 2026 18:56
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