-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
DOC: Fix DataFrame.to_xarray doctests and allow the CI to run it. #22673
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
Changes from 1 commit
670e768
a7ecbb2
ce5098a
08561d2
93edaca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2492,17 +2492,25 @@ def to_xarray(self): | |
| """ | ||
| Return an xarray object from the pandas object. | ||
|
|
||
| Return the xarray equivalent of the pandas object. `xarray | ||
| <http://xarray.pydata.org/en/stable/>`__ is a | ||
| Python package that allows to handle N-dimensional data. | ||
|
|
||
| Returns | ||
| ------- | ||
| a DataArray for a Series | ||
| a Dataset for a DataFrame | ||
| a DataArray for higher dims | ||
|
||
|
|
||
| See also | ||
| -------- | ||
| DataFrame.to_csv : Write out to a csv file. | ||
|
||
|
|
||
| Examples | ||
| -------- | ||
| >>> df = pd.DataFrame({'A' : [1, 1, 2], | ||
| 'B' : ['foo', 'bar', 'foo'], | ||
| 'C' : np.arange(4.,7)}) | ||
| ... 'B' : ['foo', 'bar', 'foo'], | ||
| ... 'C' : np.arange(4.,7)}) | ||
|
||
| >>> df | ||
| A B C | ||
| 0 1 foo 4.0 | ||
|
|
@@ -2520,9 +2528,9 @@ def to_xarray(self): | |
| C (index) float64 4.0 5.0 6.0 | ||
|
|
||
| >>> df = pd.DataFrame({'A' : [1, 1, 2], | ||
| 'B' : ['foo', 'bar', 'foo'], | ||
| 'C' : np.arange(4.,7)} | ||
| ).set_index(['B','A']) | ||
| ... 'B' : ['foo', 'bar', 'foo'], | ||
| ... 'C' : np.arange(4.,7)} | ||
| ... ).set_index(['B','A']) | ||
|
||
| >>> df | ||
| C | ||
| B A | ||
|
|
@@ -2539,35 +2547,33 @@ def to_xarray(self): | |
| Data variables: | ||
| C (B, A) float64 5.0 nan 4.0 6.0 | ||
|
|
||
| >>> p = pd.Panel(np.arange(24).reshape(4,3,2), | ||
| items=list('ABCD'), | ||
| major_axis=pd.date_range('20130101', periods=3), | ||
| minor_axis=['first', 'second']) | ||
| >>> p | ||
| <class 'pandas.core.panel.Panel'> | ||
| Dimensions: 4 (items) x 3 (major_axis) x 2 (minor_axis) | ||
| Items axis: A to D | ||
| Major_axis axis: 2013-01-01 00:00:00 to 2013-01-03 00:00:00 | ||
| Minor_axis axis: first to second | ||
|
|
||
| >>> p.to_xarray() | ||
| <xarray.DataArray (items: 4, major_axis: 3, minor_axis: 2)> | ||
| array([[[ 0, 1], | ||
| [ 2, 3], | ||
| [ 4, 5]], | ||
| [[ 6, 7], | ||
| [ 8, 9], | ||
| [10, 11]], | ||
| [[12, 13], | ||
| [14, 15], | ||
| [16, 17]], | ||
| [[18, 19], | ||
| [20, 21], | ||
| [22, 23]]]) | ||
| >>> index = pd.MultiIndex(levels=[['bar', 'baz', 'foo', 'qux'], | ||
| ... ['one', 'two']], | ||
| ... labels=[[0, 0, 1, 1, 2, 2, 3, 3], [0, 1, 0, 1, 0, 1, 0, 1]], | ||
| ... names=['first', 'second']) | ||
|
|
||
| >>> s = pd.Series(np.arange(8), index=index) | ||
| >>> s | ||
|
||
| first second | ||
| bar one 0 | ||
| two 1 | ||
| baz one 2 | ||
| two 3 | ||
| foo one 4 | ||
| two 5 | ||
| qux one 6 | ||
| two 7 | ||
| dtype: int64 | ||
|
|
||
| >>> s.to_xarray() | ||
| <xarray.DataArray (first: 4, second: 2)> | ||
| array([[0, 1], | ||
| [2, 3], | ||
| [4, 5], | ||
| [6, 7]]) | ||
| Coordinates: | ||
| * items (items) object 'A' 'B' 'C' 'D' | ||
| * major_axis (major_axis) datetime64[ns] 2013-01-01 2013-01-02 2013-01-03 # noqa | ||
| * minor_axis (minor_axis) object 'first' 'second' | ||
| * first (first) object 'bar' 'baz' 'foo' 'qux' | ||
|
||
| * second (second) object 'one' 'two' | ||
|
|
||
| Notes | ||
| ----- | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we need to mention this here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to extend the previous short summary. Do you suggest to simply remove it or is there something else we should mention here?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove it. We describe
xarrayelsewhere in the docs anyhow. You don't always have to put an extension of the short summary.