Skip to content

[py] Add to_dict() and __repr__ to PlatformConfig and PlatformSchemaConfig#4458

Merged
aaronwolen merged 3 commits into
mainfrom
aaron/soma-939-add-to_dict-and-__repr__-for-platformschemaconfig
May 5, 2026
Merged

[py] Add to_dict() and __repr__ to PlatformConfig and PlatformSchemaConfig#4458
aaronwolen merged 3 commits into
mainfrom
aaron/soma-939-add-to_dict-and-__repr__-for-platformschemaconfig

Conversation

@aaronwolen

@aaronwolen aaronwolen commented Apr 30, 2026

Copy link
Copy Markdown
Member

Issue and/or context: [SOMA-939]

The PlatformConfig and PlatformSchemaConfig attributes can only be viewed individually, with no convenient way to dump the full configuration for logging, diagnostics, etc.

Changes:

  • PlatformConfig and PlatformSchemaConfig now expose:
    • to_dict() returns a Python dict of all fields.
    • __repr__ provides a single-line representation showing each field.

Example:

import tempfile
from pprint import pprint

import pyarrow as pa

import tiledbsoma
from tiledbsoma import pytiledbsoma as clib

pc = clib.PlatformConfig()
print("\n\nrepr(pc):\n")
print(repr(pc))
print("\n\npc.to_dict():\n")
pprint(pc.to_dict())


with tempfile.TemporaryDirectory() as tmp:
    uri = f"{tmp}/sparse"
    tiledbsoma.SparseNDArray.create(uri, type=pa.float32(), shape=(100, 100)).close()
    with tiledbsoma.SparseNDArray.open(uri) as arr:
        cfg = arr.schema_config_options()
        print("\n\nrepr(cfg):\n")
        print(repr(cfg))
        print("\n\ncfg.to_dict():\n")
        pprint(cfg.to_dict())

Output:

repr(pc):

PlatformConfig(dataframe_dim_zstd_level=3, sparse_nd_array_dim_zstd_level=3, dense_nd_array_dim_zstd_level=3, write_X_chunked=True, goal_chunk_nnz=100000000, remote_cap_nbytes=2400000000, capacity=100000, offsets_filters='["DOUBLE_DELTA", "BIT_WIDTH_REDUCTION", "ZSTD"]', validity_filters='', allows_duplicates=False, tile_order=None, cell_order=None, attrs='', dims='', consolidate_and_vacuum=False)


pc.to_dict():

{'allows_duplicates': False,
 'attrs': '',
 'capacity': 100000,
 'cell_order': None,
 'consolidate_and_vacuum': False,
 'dataframe_dim_zstd_level': 3,
 'dense_nd_array_dim_zstd_level': 3,
 'dims': '',
 'goal_chunk_nnz': 100000000,
 'offsets_filters': '["DOUBLE_DELTA", "BIT_WIDTH_REDUCTION", "ZSTD"]',
 'remote_cap_nbytes': 2400000000,
 'sparse_nd_array_dim_zstd_level': 3,
 'tile_order': None,
 'validity_filters': '',
 'write_X_chunked': True}


repr(cfg):

PlatformSchemaConfig(capacity=100000, allows_duplicates=False, tile_order='row-major', cell_order='row-major', offsets_filters='[{"COMPRESSION_LEVEL":-1,"COMPRESSION_REINTERPRET_DATATYPE":17,"name":"DOUBLE_DELTA"},{"BIT_WIDTH_MAX_WINDOW":256,"name":"BIT_WIDTH_REDUCTION"},{"COMPRESSION_LEVEL":-1,"name":"ZSTD"}]', validity_filters='[{"COMPRESSION_LEVEL":-1,"name":"RLE"}]', attrs='{"soma_data":{"filters":[{"COMPRESSION_LEVEL":-1,"name":"ZSTD"}]}}', dims='{"soma_dim_0":{"filters":[{"COMPRESSION_LEVEL":3,"name":"ZSTD"}],"tile":"2048"},"soma_dim_1":{"filters":[{"COMPRESSION_LEVEL":3,"name":"ZSTD"}],"tile":"2048"}}')


cfg.to_dict():

{'allows_duplicates': False,
 'attrs': '{"soma_data":{"filters":[{"COMPRESSION_LEVEL":-1,"name":"ZSTD"}]}}',
 'capacity': 100000,
 'cell_order': 'row-major',
 'dims': '{"soma_dim_0":{"filters":[{"COMPRESSION_LEVEL":3,"name":"ZSTD"}],"tile":"2048"},"soma_dim_1":{"filters":[{"COMPRESSION_LEVEL":3,"name":"ZSTD"}],"tile":"2048"}}',
 'offsets_filters': '[{"COMPRESSION_LEVEL":-1,"COMPRESSION_REINTERPRET_DATATYPE":17,"name":"DOUBLE_DELTA"},{"BIT_WIDTH_MAX_WINDOW":256,"name":"BIT_WIDTH_REDUCTION"},{"COMPRESSION_LEVEL":-1,"name":"ZSTD"}]',
 'tile_order': 'row-major',
 'validity_filters': '[{"COMPRESSION_LEVEL":-1,"name":"RLE"}]'}

Notes for Reviewer:

PR includes two other fixes:

  • Fixed the schema_config_options docstring which incorrectly said the method returned a PlatformConfig, rather than a PlatformSchemaConfig.
  • PlatformConfig.dense_nd_array_dim_zstd_level is now bound to the correct C++ member.

The pybind11 binding for `PlatformConfig.dense_nd_array_dim_zstd_level`
was aliased to `&PlatformConfig::sparse_nd_array_dim_zstd_level`, so
mutations to the dense level silently overwrote the sparse level and
reads always returned the sparse level. Bind it to the correct member.

Adds a regression test that verifies both fields can be set and read
back independently.
…rmSchemaConfig

Both pybind11-bound config structs now expose:

* `to_dict()` — returns a Python dict of all fields, useful for
  diagnostic logging, serialization, and structural comparison.
* `__repr__` — readable single-line representation showing each field
  and its current value. The optional fields `tile_order` and
  `cell_order` render as `None` when unset and `'value'` when set.
@codecov

codecov Bot commented Apr 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.26%. Comparing base (3d46320) to head (72eec7b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4458      +/-   ##
==========================================
- Coverage   85.27%   85.26%   -0.01%     
==========================================
  Files         136      136              
  Lines       21266    21266              
==========================================
- Hits        18135    18133       -2     
- Misses       3131     3133       +2     
Flag Coverage Δ
python 88.42% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
python_api 88.42% <ø> (-0.03%) ⬇️
libtiledbsoma ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aaronwolen aaronwolen marked this pull request as ready for review April 30, 2026 20:46
@aaronwolen aaronwolen requested a review from jp-dark April 30, 2026 20:47
@aaronwolen aaronwolen merged commit 2ed76cb into main May 5, 2026
16 checks passed
@aaronwolen aaronwolen deleted the aaron/soma-939-add-to_dict-and-__repr__-for-platformschemaconfig branch May 5, 2026 17:59
jp-dark pushed a commit that referenced this pull request May 15, 2026
…SchemaConfig` (#4458) (#4460)

* fix(python): bind dense_nd_array_dim_zstd_level to the correct field

The pybind11 binding for `PlatformConfig.dense_nd_array_dim_zstd_level`
was aliased to `&PlatformConfig::sparse_nd_array_dim_zstd_level`, so
mutations to the dense level silently overwrote the sparse level and
reads always returned the sparse level. Bind it to the correct member.

Adds a regression test that verifies both fields can be set and read
back independently.

* feat(python): add to_dict() and __repr__ to PlatformConfig and PlatformSchemaConfig

Both pybind11-bound config structs now expose:

* `to_dict()` — returns a Python dict of all fields, useful for
  diagnostic logging, serialization, and structural comparison.
* `__repr__` — readable single-line representation showing each field
  and its current value. The optional fields `tile_order` and
  `cell_order` render as `None` when unset and `'value'` when set.

* docs(python): correct schema_config_options return type in docstring

(cherry picked from commit 2ed76cb)

Co-authored-by: Aaron Wolen <aaron@wolen.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants