Skip to content

TST: add test for converting 0-len Series #697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jreback opened this issue Jan 2, 2016 · 7 comments
Closed

TST: add test for converting 0-len Series #697

jreback opened this issue Jan 2, 2016 · 7 comments

Comments

@jreback
Copy link

jreback commented Jan 2, 2016

are these supported?

In [3]: xray.DataArray.from_series(Series([]))
ValueError: dimensions () must have the same length as the number of data dimensions, ndim=1

In [5]: xray.Dataset.from_dataframe(DataFrame({'A' : []}))
ValueError: dimensions () must have the same length as the number of data dimensions, ndim=1
@shoyer
Copy link
Member

shoyer commented Jan 3, 2016

These definitely should work.

@MaximilianR did your fix handle Series -> DataArray? Let's leave this open if not...

@shoyer shoyer reopened this Jan 3, 2016
@max-sixty
Copy link
Collaborator

@shoyer Was that ever a problem?

In [36]: xray.DataArray(pd.Series())
Out[36]: 
<xray.DataArray (dim_0: 0)>
array([], dtype=float64)
Coordinates:
  * dim_0    (dim_0) object 

In [37]: xray.DataArray(pd.Series(range(20)))
Out[37]: 
<xray.DataArray (dim_0: 20)>
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
       17, 18, 19])
Coordinates:
  * dim_0    (dim_0) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

@shoyer
Copy link
Member

shoyer commented Jan 3, 2016

@jreback's first case uses the from_series constructor.

@max-sixty
Copy link
Collaborator

Ah yes, that goes through the same path as the empty DataFrame. Alas I didn't add a test, but it works

@max-sixty
Copy link
Collaborator

TBC, this does work, even if it's not tested:

In [11]: xr.DataArray.from_series(pd.Series())
Out[11]: 
<xarray.DataArray (index: 0)>
array([], dtype=float64)
Coordinates:
  * index    (index) object 

@shoyer shoyer changed the title BUG: support 0-len Series/DataFrame TST: add test for converting 0-len Series Feb 2, 2016
@shoyer
Copy link
Member

shoyer commented Feb 2, 2016

@MaximilianR Just updated the title of this issue to match

@stale
Copy link

stale bot commented Jan 29, 2019

In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity
If this issue remains relevant, please comment here; otherwise it will be marked as closed automatically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants