You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
setitem with repeated indices is not guaranteed in practice #2855
behaviour of setitem with repeated indices depends on platform. The example below succeeds on Mac and fails on ubuntu, windows with numpy 2.2. It succeeds in all CI environments with numpy 1.25.
following up on this because we have a few open PRs about it:
numpy documents its write order as an implementation detail that could change: https://numpy.org/devdocs/user/basics.indexing.html#detailed-notes. I think we want to make the same claim for zarr, because that gives us flexibility. Users who want stable behavior should rewrite their indexing expressions to be unambiguous. This needs to be documented.
the platform dependence is due to varying implementations of argsort, which are unstable sorts on some platforms. a stable sort keeps things consistent across platforms
the de-duplication I proposed upthread is more expensive perf-wise than keeping user input as-is and following a heuristic like last-write wins, so I don't think rewriting the indexing expression is worth it
Activity
d-v-b commentedon Feb 24, 2025
is numpy's behavior also platform-dependent? If not, then I think we should copy numpy here. On my OSX machine, numpy uses the last value assigned:
We probably need to transform the input such that it defines an indexing operation that only applies 1 change to each output index.
LDeakin commentedon Feb 24, 2025
That'd be perfect
dcherian commentedon Feb 24, 2025
numpy behaviour is always consistent and pretty well-defined since it's serial.
I don't understand what's going on here. transforming the input does seem sensible.
d-v-b commentedon Nov 18, 2026
following up on this because we have a few open PRs about it:
zarr, because that gives us flexibility. Users who want stable behavior should rewrite their indexing expressions to be unambiguous. This needs to be documented.argsort, which are unstable sorts on some platforms. a stable sort keeps things consistent across platforms