Skip to content

Create DataArray with empty .data? #9120

Answered by ghbrown
ghbrown asked this question in General
Jun 13, 2024 · 4 comments · 16 replies
Discussion options

You must be logged in to vote

Thanks to @TomNicholas and @dcherian for the many answers and suggestions, this comprehensive answer just puts all the information in one spot for future readers.

Answer

It's not directly possible to have and empty .data attribute, but using a sparse.COO array of the correct shape with no nonzeros results in negligible memory usage. At the time of writing scipy.sparse.coo_array was not supported as an input to DataArray() and gave an error (see #7280).
It may also be possible to use a view of an array by setting
data=np.broadcast_to(np.array([0]), <your shape>)
but when trying to save the resulting xarray.DataArray as a pickle this resulted in memory usage proportional to the size of the …

Replies: 4 comments 16 replies

Comment options

You must be logged in to vote
6 replies
@dcherian
Comment options

@ghbrown
Comment options

@dcherian
Comment options

@ghbrown
Comment options

@TomNicholas
Comment options

Comment options

You must be logged in to vote
10 replies
@ghbrown
Comment options

@TomNicholas
Comment options

@TomNicholas
Comment options

@ghbrown
Comment options

@keewis
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by ghbrown
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants