Skip to content

Fix truncated string accessor results on dask arrays - #11962

Open
vsaraikin wants to merge 1 commit into
pydata:mainfrom
vsaraikin:str-accessor-dask-truncation
Open

vsaraikin wants to merge 1 commit into
pydata:mainfrom
vsaraikin:str-accessor-dask-truncation

Conversation

@vsaraikin

Copy link
Copy Markdown
Contributor

Description

String accessor methods that return strings and still go elementwise (cat, +, upper, format, regex replace, ...) gave truncated results on dask arrays. There are two reasons. dask calls np.vectorize with a signature, which allocates a U1/S1 output (numpy/numpy#8352), so these now use an object output on chunked data. And each chunk gets its own string width, but the chunks are concatenated with the dtype of the first one, so wider later chunks were cut. This also affected the np.strings path from #11746 when the first chunk is not the widest, e.g. da.chunk(1).str * 3. The new _astype_str casts all chunks to the largest width.

The computed result now has the same values and dtype as on numpy arrays. The cost is that the largest width needs all chunks, so they stay in memory until the last one is done. The alternative would be to return object arrays on dask and leave the width alone, I can change it to that if you prefer.

split/rsplit with dim, extractall and get_dummies still fail on dask arrays. Their output size depends on the data, so I left them out.

Checklist

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.
    • Tools: Claude Code

@vsaraikin
vsaraikin force-pushed the str-accessor-dask-truncation branch from fe23ed4 to f08ec60 Compare December 1, 2026 08:28

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xarray.DataArray.str.cat() doesn't work on chunked data

1 participant