Load and build indices lazily
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 38/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Ambito
- data, performance
Direzione di ricerca
Inizia tracciando create_default_indices e create_default_index_implicit attraverso il percorso di caricamento degli indici, quindi esamina le responsabilità di PandasIndex, PandasIndexingAdapter e dei proposti LazyDefaultIndex e LazyIndexingAdapter. La funzionalità è completa quando la semantica dell’indice predefinito viene preservata mentre i valori dell’indice vengono caricati solo quando necessario, incluse le operazioni elencate che non causano la materializzazione e il riutilizzo tra copie.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Is your feature request related to a problem?
Yes. Currently, when you load a datatree/set, all the coordinates are loaded eagerly, and indices built. I believe the loading is also synchronous, so you end up paying a performance penalty for things you might not even want.
Initially, I thought I could use create_default_indices=False to fix this, because indices are created automatically when needed. But setting that flag changes the semantics of index loading for data trees. Initially I wrote this up as a bug, but then it appears that this is deliberate behaviour.
Describe the solution you'd like
I would like an option that has the same semantics as create_default_indices=True, but defers creation until necessary. Perhaps create_default_indices="lazy".
A very simple example use case would be loading a datatree just so you can inspect the metadata (e.g. shapes). But or loading a large datatree, but only actually using a subtree of it.
Describe alternatives you've considered
- Just live with the perf hit and wasted bandwidth.
- Use create_default_indices=False, and be very careful with issues this can cause.
Additional context
I've prototyped a solution for this already.
My solution involves create LazyDefaultIndex, which inherits from Index. This object will load the actual value, a PandasIndex via create_default_index_implicit once the index is required for operations. On datatree creation, this object is filled in any indices, where PandasIndex would normally go. Because this is an actual object, it has similar resolution
Similarly, define LazyIndexingAdapter from PandasIndexingAdapter.
Both these lazy objects hold the actual index in a mutable box, so that the actual index is only loaded once, and re-used, regardless of copy operations. Indices are immutable, so this is safe.
Some methods don't always materialize the index:
- from_variables / create_variables / copy (returns another lazy object sharing same data)
- rename (can return a lazy object , but doesnt share)
- dim / repr (doesn't use index directly)
- equals (if it can determine they share the same mutable box)
- isel / roll (depending on arguments)
This works well enough in my code base, it's about 400 lines of code, but it depends on xarray internals:
- It has to duck type PandasIndexingAdapter quite closely.
- It has to inherit from PandasIndexingAdapator from it to pass a few isinstance checks.
- A few
Selftyped methods have to be acceptSelf | PandasIndex, and returnPandasIndex, subtly changing some contracts. - When pretty printing, it does get the same
*marker that normal indices do, even after materialization.
If I were to incorpate into xarray, I'd probably make a base class AbstractPandasIndex, form which LazyPandasIndex and PandasIndex inherit, and interoperate.
I'm happy to share my code / incoporate into xarray if this seems like a good direction. But xarray's semantics are a bit tricky, I thought it best to discuss first.
- Lingua principale
- Python
- Stelle
- 4.2k
- Fork
- 1.5k
- Merge medio
- 2g 21h
- PR unite (30g)
- 74
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pydata/xarray
-
xarray removes axis grid from pcolormeshForse già presa @Sealdot l’ha presa oggi. Apertabug needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
`DataTree.map_over_datasets` behavior can be obscure sometimesForse già presa @mohansree14 l’ha presa 24 giorni fa. Apertaneeds triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
pydata/xarray#11813 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Comparing attrs that contain a dict of NumPy arrays raises ValueError in identical / assert_identicalForse già presa @SohamXYZDev l’ha presa 29 giorni fa. Apertabug needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
pydata/xarray#11777 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
RangeIndex` with datetime64 bounds cannot be printed (`Unknown format code 'g'`)Forse già presa @d-chambers l’ha presa 60 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
pydata/xarray#11598 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
DataTree constructor error message says dict even though dict is not acceptedForse già presa @aryansk l’ha presa 100 giorni fa. Apertabug contrib-good-first-issue topic-DataTree topic-error reporting
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
pydata/xarray#11514 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di pydata/xarray
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
abetlen/llama-cpp-python#2424 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug IronPython Python 3
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
pyrevitlabs/pyRevit#4184 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 74/100
jqueryscript/awesome-claude-code#1009 ·
-
tests
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno