Skip to content

feat(py_qubed): ergonomic Python API with immutable ops and new surface#108

Draft
HCookie wants to merge 1 commit into
mainfrom
feat/python-api-ergonomics
Draft

feat(py_qubed): ergonomic Python API with immutable ops and new surface#108
HCookie wants to merge 1 commit into
mainfrom
feat/python-api-ergonomics

Conversation

@HCookie

@HCookie HCookie commented Jun 23, 2026

Copy link
Copy Markdown
Member

Summary

Overhauls the Python API for ergonomics, safety, and Pythonic conventions. This is the largest PR in the split and includes all underlying Rust changes needed to support the new surface.

Breaking changes

Before After
PyQube class name Qube
drop() mutates in place Returns new Qube
squeeze() mutates in place Returns new Qube
to_datacubes() returns strings Returns native types (int/float/str)
from_arena_json(str) from_arena_json(str | dict)

New API surface

  • Qube.empty(), Qube.is_empty()
  • Qube.from_json() / to_json() (nested key=value format)
  • Qube.from_tree_json() / to_tree_json()
  • axes() (alias for all_unique_dim_coords)
  • dimensions() returns set[str]
  • __or__ operator (a | b) for non-mutating merge
  • __copy__ / __deepcopy__ support
  • from_datacube preserves Python dict insertion order as default dimension ordering
  • Datacube dicts accept list, int, float values (not just strings)

Included Rust changes

This PR bundles the Rust-level fixes that the Python API depends on:

Tests & docs

  • All tests updated for Qube class name and native-type returns
  • New tests for JSON/tree-JSON roundtrips, copy/deepcopy, | operator, immutable drop/squeeze, axes(), dimensions()
  • New test_qubed_initialisation.py for Qube.empty()
  • docs/src/python/py_qubed.md rewritten for new API

Part of the split from #102. Independently mergeable (includes all dependencies).

Breaking changes:
- Class renamed from PyQube to Qube on the Python side
- drop() and squeeze() now return a new Qube instead of mutating
- to_datacubes() and all_unique_dim_coords() return native Python types
- from_arena_json() now accepts str | dict

New API surface:
- Qube.empty(), Qube.is_empty()
- Qube.from_json() / to_json() (nested key=value format)
- Qube.from_tree_json() / to_tree_json()
- axes() (alias for all_unique_dim_coords)
- dimensions() returns set[str]
- __or__ operator (a | b) for non-mutating merge
- __copy__ / __deepcopy__ support
- from_datacube preserves Python dict insertion order
- Datacube dicts accept list, int, float values (not just strings)

Also includes all Rust-level fixes required for the Python API:
- Coordinate intersection safety and leading-zero consistency
- Merge dimension translation map for cross-Qube safety
- Tree JSON serialisation format
- Deterministic from_datacube ordering

Tests updated for new API, docs rewritten.
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