Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

from_dataset re-reads every dimension coordinate on each call, and the workaround loses the cftime UDF and template registry

Aperta
#238 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
python, sql
Ambito
api, data

Direzione di ricerca

Start in XarrayContext.from_dataset, where coord_arrays is built once per call, and in read_xarray_table, which already takes coord_arrays. Also check _registered_datasets and _maybe_register_cftime_udf. Done means one Dataset can register several per-variable tables with each dimension coordinate read once, while metadata recovery and the cftime() UDF still work. The issue proposes two API shapes and the maintainers have not picked one, so confirm the direction before coding.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem

XarrayContext.from_dataset materialises the dimension coordinates once per call:

coord_arrays = {
    str(dim): input_table.coords[dim].values for dim in input_table.dims
}

Within a single call those arrays are shared across every dim group, which is what the comment above them describes. Across calls nothing is shared. Registering one table per data variable, which is what you want when each variable should be its own SQL table, re-reads every coordinate once per variable.

Measured with a counting DataArray.values property, 4 data variables on a (time, lat, lon) grid:

4 x from_dataset (one per data var): 12 coord reads
1 x from_dataset (whole dataset)   : 3 coord reads

Local NumPy makes this free. On a Zarr store each read is a network round trip, so registration cost scales with n_vars * n_dims instead of n_dims.

The obvious workaround is not equivalent

read_xarray_table already accepts coord_arrays, so the natural caller-side fix is to read the coordinates once and register the tables directly:

shared = {str(d): ds.coords[d].values for d in ds.dims}
ctx = XarrayContext()
for v in ds.data_vars:
    ctx.register_table(v, read_xarray_table(ds[[v]], chunks, coord_arrays=shared))

That does share the reads, but bypassing from_dataset silently drops two things it does.

  1. self._registered_datasets[name] = input_table is never populated, so XarrayDataFrame loses metadata recovery. Checked: _registered_datasets is {} afterwards, and to_dataset() then returns empty attrs and cannot infer dims.

  2. _maybe_register_cftime_udf never runs, so the cftime() UDF is missing on a 360_day dataset:

cftime() escape hatch : ERR ValueError Error during planning: Invalid function 'cftime'. Did you mean 'to_time'?
cftime() from_dataset : 4 rows

So today there is no public way to register several tables out of one Dataset without either paying n_vars * n_dims coordinate reads or giving up metadata recovery and cftime support.

Possible directions

Either shape would fix it:

  • Accept coord_arrays on from_dataset (the parameter already exists one layer down in read_xarray_table), so a caller registering several tables from one parent Dataset can hand in the arrays it already read.
  • Add a per-variable split to from_dataset, alongside the existing dim-group split, so a single call can register air, hum and so on as separate tables from one Dataset. This keeps the coordinate sharing, the _registered_datasets tracking and the cftime UDF registration together in one place.

Parent: #126

Lingua principale
Python
Stelle
142
Fork
19
Merge medio
1g 9h
PR unite (30g)
9

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di xqlsystems/xarray-sql

Tutte le issue di xqlsystems/xarray-sql

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.