Repository navigation
perf(model): relabel assign_coords containers without a label dict - #1030
Open
olivier-lacroix wants to merge 1 commit into
Open
olivier-lacroix wants to merge 1 commit into
olivier-lacroix wants to merge 1 commit into
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
olivier-lacroix
force-pushed
the
perf/assign-coords-relabel
branch
3 times, most recently
from
October 11, 2026 12:21
14e9d58 to
824d1f0
Compare
olivier-lacroix
marked this pull request as ready for review
October 11, 2026 12:22
olivier-lacroix
force-pushed
the
perf/assign-coords-relabel
branch
from
October 20, 2026 22:33
824d1f0 to
4739b55
Compare
Model.assign_coords rebuilt a master->new dict per container and mapped each container's labels through Index.map. On a tz-aware DatetimeIndex that map falls into pandas' object-to-datetime inference, costing milliseconds per container. Map full-length containers straight to the new values and locate subset containers' labels with get_indexer/take, and build a reassigned Dataset once instead of twice. ~817 ms -> ~3 ms for 30 containers on a 4380-label tz-aware axis. Co-Authored-By: Claude Code <noreply@anthropic.com>
olivier-lacroix
force-pushed
the
perf/assign-coords-relabel
branch
from
October 27, 2026 03:11
dbf4c67 to
663a15c
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Taking assign_coords for a spin, I realised it was way too slow. this PR fixes it. Sorry for not catching this sooner...
Note
The following content was generated by AI.
What
Model.assign_coords(from #955) relabelled containers by rebuilding amaster -> newdict per container and mapping each container's labels throughIndex.map. On a tz-awareDatetimeIndex— the rolling-horizon case the API is built for — that map falls into pandas' object-to-datetime inference (maybe_infer_to_datetimelike->objects_to_datetime64), costing milliseconds per container; the dict was also rebuilt once per container.Two changes, both inside the #955 code:
master.get_indexer(index)andnew.take(positions).get_indexeralso replaces the separateindex.isin(master).all()guard, folding the membership check and the mapping into one C-level lookup.Datasetconstruction.assign_coords_multiindex_safewrites the new index into the coordinate's original position and builds the dataset once, instead ofDataset.assign_coords(...)followed by a secondDataset(...)to restore the coordinate order thatassign_coordsbreaks.Benchmark
30 containers (15 variables + 15 CSR constraints), 4380 tz-aware labels,
Model(sparse=True), v1 semantics:Model.assign_coordsReproduction
Checklist
AGENTS.md).doc.doc/release_notes.rstof the upcoming release is included.