question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Creation of an empty DataArray

See original GitHub issue

I’d like to create an empty DataArray, i.e., one with only NA values. The docstring of DataArray says that data=None is allowed, if a dataset argument is provided. However, the docstring doesn’t say anything about a dataset argument.

  1. I think there’s a bug in the docstring
  2. I’d like to pass data=None and get a DataArray with the coords/dims set up properly (as defined by the coords and dims kwargs), but with a values array of NA.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:10
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

7reactions
aldanorcommented, May 10, 2019

It might also make sense then to implement all numpy-like constructors for DataArray, plus the empty(), which is typically faster for larger arrays:

  • .full() (kind of what’s suggested here)
  • .ones()
  • .zeros()
  • .empty()

This should be trivial to implement.

1reaction
shoyercommented, Dec 22, 2014

Fixed the doc string for now, but this would still be a nice feature to add at some point.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Most straightforward/compact way to iteratively create ...
If you known coordinates beforehand, then you can initialize an empty DataArray, which is almost your last example. >>> da = xr.
Read more >
xarray.DataArray
DataArray provides a wrapper around numpy ndarrays that uses labeled dimensions and coordinates to support metadata aware operations. The API is similar to...
Read more >
How to create an xarray dataset from scratch - The Urbanist
This is just a code snippet to remind myself how to build an xarray dataset. Note: this post has been updated with further...
Read more >
Basic data structures of xarray - Towards Data Science
The 2 basic data structures of xarray are introduced with examples on how to create DataArray and Dataset in xarray for beginners.
Read more >
xarray.DataArray — xarray 0.7.1 documentation
DataArray provides a wrapper around numpy ndarrays that uses labeled dimensions and ... By default, an empty attribute dictionary is initialized.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found