Skip to content

[WIP] ENH: add to_xarray conversion method #11950

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
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
xray -> xarray
  • Loading branch information
jreback committed Jan 6, 2016
commit ceda3dd989de506d7a30fb0a6e0fecef494f519d
4 changes: 2 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,9 +1041,9 @@ def to_clipboard(self, excel=None, sep=None, **kwargs):
from pandas.io import clipboard
clipboard.to_clipboard(self, excel=excel, sep=sep, **kwargs)

def to_xray(self):
def to_xarray(self):
"""
Return an xray object from the pandas object.
Return an xarray object from the pandas object.

Returns
-------
Expand Down
38 changes: 19 additions & 19 deletions pandas/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,17 +1034,17 @@ def test_describe_none(self):
expected = Series([0, 0], index=['count', 'unique'], name='None')
assert_series_equal(noneSeries.describe(), expected)

def test_to_xray(self):
def test_to_xarray(self):

tm._skip_if_no_xray()
tm._skip_if_no_xarray()
import xray
from xray import DataArray

if LooseVersion(xray.__version__) > '0.6.1':
# https://github.com/xray/xray/issues/697
s = Series([])
s.index.name = 'foo'
result = s.to_xray()
result = s.to_xarray()
self.assertEqual(len(result), 0)
self.assertEqual(len(result.coords), 1)
self.assertEqual(result.coords.keys(), ['foo'])
Expand All @@ -1056,7 +1056,7 @@ def test_to_xray(self):
tm.makeTimedeltaIndex]:
s = Series(range(6), index=index(6))
s.index.name = 'foo'
result = s.to_xray()
result = s.to_xarray()
repr(result)
self.assertEqual(len(result), 6)
self.assertEqual(len(result.coords), 1)
Expand All @@ -1072,12 +1072,12 @@ def test_to_xray(self):
s = Series(range(6), index=index(6))
s.index.name = 'foo'

result = s.to_xray()
result = s.to_xarray()
self.assertRaises(ValueError, lambda: repr(result))

s.index = pd.MultiIndex.from_product([['a', 'b'], range(3)],
names=['one', 'two'])
result = s.to_xray()
result = s.to_xarray()
self.assertEqual(len(result), 2)
assert_almost_equal(result.coords.keys(), ['one', 'two'])
self.assertIsInstance(result, DataArray)
Expand Down Expand Up @@ -1766,9 +1766,9 @@ def test_pct_change(self):

self.assert_frame_equal(result, expected)

def test_to_xray(self):
def test_to_xarray(self):

tm._skip_if_no_xray()
tm._skip_if_no_xarray()
import xray
from xray import Dataset

Expand All @@ -1785,9 +1785,9 @@ def test_to_xray(self):
)

if LooseVersion(xray.__version__) > '0.6.1':
# https://github.com/xray/xray/issues/697
# https://github.com/pydata/xarray/issues/697
df.index.name = 'foo'
result = df[0:0].to_xray()
result = df[0:0].to_xarray()
self.assertEqual(result.dims['foo'], 0)
self.assertIsInstance(result, Dataset)

Expand All @@ -1798,7 +1798,7 @@ def test_to_xray(self):
df.index = index(3)
df.index.name = 'foo'
df.columns.name = 'bar'
result = df.to_xray()
result = df.to_xarray()
self.assertEqual(result.dims['foo'], 3)
self.assertEqual(len(result.coords), 1)
self.assertEqual(len(result.data_vars), 8)
Expand All @@ -1820,26 +1820,26 @@ def test_to_xray(self):
# not implemented
df.index = pd.MultiIndex.from_product([['a'], range(3)],
names=['one', 'two'])
self.assertRaises(ValueError, lambda: df.to_xray())
self.assertRaises(ValueError, lambda: df.to_xarray())


class TestPanel(tm.TestCase, Generic):
_typ = Panel
_comparator = lambda self, x, y: assert_panel_equal(x, y)

def test_to_xray(self):
def test_to_xarray(self):

tm._skip_if_no_xray()
tm._skip_if_no_xarray()
import xray
from xray import Dataset

p = tm.makePanel()

if LooseVersion(xray.__version__) > '0.6.1':
# https://github.com/xray/xray/issues/697
# https://github.com/pydata/xarray/issues/697
pass

result = p.to_xray()
result = p.to_xarray()
self.assertIsInstance(result, Dataset)
self.assertEqual(len(result.coords), 3)
assert_almost_equal(result.coords.keys(),
Expand All @@ -1851,9 +1851,9 @@ class TestPanel4D(tm.TestCase, Generic):
_typ = Panel4D
_comparator = lambda self, x, y: assert_panel4d_equal(x, y)

def test_to_xray(self):
def test_to_xarray(self):

tm._skip_if_no_xray()
tm._skip_if_no_xarray()
import xray
from xray import Dataset

Expand All @@ -1863,7 +1863,7 @@ def test_to_xray(self):
# https://github.com/xray/xray/issues/697
pass

result = p.to_xray()
result = p.to_xarray()
self.assertIsInstance(result, Dataset)
self.assertEqual(len(result.coords), 4)
assert_almost_equal(result.coords.keys(),
Expand Down
4 changes: 2 additions & 2 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ def _skip_if_no_scipy():
raise nose.SkipTest('scipy.interpolate missing')


def _skip_if_no_xray():
def _skip_if_no_xarray():
try:
import xray
except ImportError:
import nose
raise nose.SkipTest("xray not installed")
raise nose.SkipTest("xarray not installed")


def _skip_if_no_pytz():
Expand Down