Skip to content

Sparse set_atom_data with by_species and by_index (closes #65)#72

Merged
bjmorgan merged 15 commits intomainfrom
sparse-atom-data
Apr 12, 2026
Merged

Sparse set_atom_data with by_species and by_index (closes #65)#72
bjmorgan merged 15 commits intomainfrom
sparse-atom-data

Conversation

@bjmorgan
Copy link
Copy Markdown
Owner

Summary

  • set_atom_data gains by_species and by_index keyword arguments for sparse per-atom metadata assignment. by_species maps species labels to scalar, 1-D, or 2-D values; by_index maps atom indices to scalar or 1-D values. Both can be combined in one call, with by_index taking precedence at overlapping atoms.
  • set_atom_data no longer accepts a dict as its positional values argument -- use by_index= instead.
  • Missing entries in sparse categorical atom data are now filled with None (object-dtype) instead of empty strings.
  • 2-D by_species values or 1-D by_index values promote the output to (n_frames, n_atoms). Scalar and 1-D by_species values broadcast across frames automatically.

Closes #65.

_coerce_sparse_atom_data now infers dtype from the supplied values:
numeric values produce a float array with NaN fill; string values produce
an object-dtype array with None fill; mixed types raise TypeError.
Passing a dict to values= now raises TypeError with a pointer to
by_index=.  All existing dict-in-values call sites in the tests have
been migrated to by_index=.  The test_sparse_dict_empty_raises test is
deleted (covered by the pre-existing test_all_omitted_raises).
Copilot AI review requested due to automatic review settings April 12, 2026 08:21

This comment was marked as resolved.

Copilot AI review requested due to automatic review settings April 12, 2026 08:35

This comment was marked as resolved.

Copilot AI review requested due to automatic review settings April 12, 2026 10:33
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends StructureScene.set_atom_data to support sparse per-atom metadata assignment via by_species and by_index, updates the documentation/examples accordingly, and adjusts tests to reflect the new API (including disallowing dicts as positional values).

Changes:

  • Add _coerce_sparse_atom_data() and new set_atom_data(..., by_species=..., by_index=...) sparse assignment forms, with by_index precedence and 1-D→2-D promotion rules.
  • Remove support for passing a dict as positional values (now a TypeError), and update examples/usages to use by_index=.
  • Update docs/tests for categorical sparse fill semantics (None rather than empty string).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/hofmann/model/structure_scene.py Implements sparse coercion and new set_atom_data API/validation paths.
tests/test_model/test_structure_scene.py Adds comprehensive coverage for by_species/by_index, promotion rules, precedence, and new error behavior.
tests/test_rendering/test_painter.py Migrates rendering tests to the new by_index= sparse form.
src/hofmann/model/colour.py Updates documentation example code to use by_index=.
docs/colouring.rst Documents sparse assignment and updates missing categorical sentinel to None.
docs/changelog.rst Adds user-facing changelog entries for the new API and behavior changes.
docs/_static/generate_images.py Updates image-generation script calls to use by_index=.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/hofmann/model/structure_scene.py
Copilot AI review requested due to automatic review settings April 12, 2026 10:49
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends StructureScene.set_atom_data() to support sparse per-atom metadata assignment via by_species and by_index, updates documentation/examples accordingly, and adjusts tests to reflect the new API (including the removal of dict-as-positional-values).

Changes:

  • Add sparse metadata coercion (by_species/by_index) with precedence and 1-D/2-D promotion rules.
  • Deprecate/remove dict positional values input in favor of by_index=.
  • Update tests and docs to use the new sparse assignment forms and to document None as the categorical “missing” fill value.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_rendering/test_painter.py Updates rendering tests to use by_index= instead of dict positional values.
tests/test_model/test_structure_scene.py Replaces old sparse-dict tests with comprehensive by_species/by_index coverage and new error expectations.
src/hofmann/model/structure_scene.py Implements _coerce_sparse_atom_data() and extends set_atom_data() signature/validation/docs.
src/hofmann/model/colour.py Updates docstring examples to use by_index= sparse form.
docs/colouring.rst Documents sparse assignment patterns and updates missing categorical sentinel from "" to None.
docs/changelog.rst Adds changelog entries for the new sparse API and behavioral changes.
docs/_static/generate_images.py Updates image-generation script to use by_index= for sparse calls.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/hofmann/model/structure_scene.py
@bjmorgan bjmorgan merged commit 1481c1e into main Apr 12, 2026
9 checks passed
@bjmorgan bjmorgan deleted the sparse-atom-data branch April 12, 2026 10:55
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.

Reintroduce set_atom_data with sparse by_species and by_index forms

2 participants