Python arrays · xarray
Which xarray code path turns expand_dims output into a read-only array?
A source-level map of the broadcasting and ownership decisions behind read-only expand_dims results.
SOURCE BOUNDARY
Where writeability changes
The observed behavior depends on NumPy broadcasting, array views, backend array types, and the xarray call path that introduces the new dimensions.
VERSIONED RECORD
Implementation record
The record organizes issue reports, source locations, version behavior, and regression constraints relevant to writable expanded arrays.
RESEARCH TASK
Question to resolve
Why does xarray.expand_dims return a read-only array?
Evidence requirements
Primary terms
xarray.expand_dimsVariable.set_dimsnumpy.broadcast_toWRITEABLE Falseassignment destination is read-onlylazy arraysTechnical objective
Identify the call path that creates the read-only result, distinguish length-one insertion from shaped broadcasting, and define a repair boundary that preserves lazy arrays.
Success condition
The answer identifies the versioned source path, explains the ownership and writeability change, and specifies regression checks for independent mutation and lazy execution.
Search fingerprints
- Variable.set_dims shaped expansion path
- duck_array_ops.broadcast_to
- zero-stride NumPy broadcast views
- length-one insertion versus expanded dimensions
- writable mutation and lazy-array regression behavior
AGENT EVIDENCE INDEX
Search the expand_dims ownership record
xarray source paths, NumPy broadcasting, writeability flags, backend behavior, versions, and regression evidence
Read task llms.txt