scverse / scverse/spatialdata

Drop `region` (`region_key` and `instance_key` are enough)

Open
#629 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

element: table 📑
Dominant language
Python
Stars
394
Forks
95
Avg merge
4d 3h
Merged PRs (30d)
7

Description

Motivation

The region metadata field was introduced at the storage format level to be able to tell which elements a table is annotating, without the need to examine the data in the table.

In memory the region metadata is redundant, as region can be computed on-the-fly looking at

adata = sdata.tables['my_table']
region_key = adata.uns['spatialdata_attrs']['region_key']
region = adata.obs[region_key].cat.categories

(the above assumes that the region_key column is categorical, which is already a requirement for certain plotting functions and operations (such as rasterize_bins())).

Dropping region will simplify the syntax when dealing with tables. For instance now when calling set_table_annotates_spatialelement(), the user needs to adjust the region metadata manually.

Plan

With this issue we propose (@melonora and I) to:

  • drop the region metadata in-memory
  • when writing, compute the metadata as above
  • when reading, ignoring the region metadata
  • provide a property computed as above for convenience (since the above code is verbose).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing table metadata through the in-memory model and its read/write paths, including set_table_annotates_spatialelement(). Check how region_key, instance_key, and region are currently handled. Done means region is absent in memory, computed when writing, ignored when reading, and exposed through a convenience property.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.