Skip to content

Commit 62e616e

Browse files
committed
xfail only on xarray < 0.10.0
1 parent 744dcd3 commit 62e616e

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

pandas/tests/generic/test_frame.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from operator import methodcaller
55
from copy import deepcopy
6+
from distutils.version import LooseVersion
67

78
import pytest
89
import numpy as np
@@ -18,6 +19,12 @@
1819
import pandas.util.testing as tm
1920
from .test_generic import Generic
2021

22+
try:
23+
import xarray
24+
_XARRAY_INSTALLED = True
25+
except ImportError:
26+
_XARRAY_INSTALLED = False
27+
2128

2229
class TestDataFrame(Generic):
2330
_typ = DataFrame
@@ -165,7 +172,9 @@ def test_set_attribute(self):
165172
assert df.y == 5
166173
assert_series_equal(df['y'], Series([2, 4, 6], name='y'))
167174

168-
@pytest.mark.xfail(reason="returning MultiIndex")
175+
@pytest.mark.skipif(_XARRAY_INSTALLED and
176+
LooseVersion(xarray.__version__) < '0.10.0',
177+
reason='xarray >= 0.10.0 required')
169178
@pytest.mark.parametrize(
170179
"index", ['FloatIndex', 'IntIndex',
171180
'StringIndex', 'UnicodeIndex',

pandas/tests/generic/test_series.py

+10-26
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
import pandas.util.testing as tm
1818
from .test_generic import Generic
1919

20+
try:
21+
import xarray
22+
_XARRAY_INSTALLED = True
23+
except ImportError:
24+
_XARRAY_INSTALLED = False
25+
2026

2127
class TestSeries(Generic):
2228
_typ = Series
@@ -166,15 +172,16 @@ def finalize(self, other, method=None, **kwargs):
166172
Series._metadata = _metadata
167173
Series.__finalize__ = _finalize
168174

169-
@pytest.mark.xfail(reason="returning MultiIndex")
175+
@pytest.mark.skipif(_XARRAY_INSTALLED and
176+
LooseVersion(xarray.__version__) < '0.10.0',
177+
reason='xarray >= 0.10.0 required')
170178
@pytest.mark.parametrize(
171179
"index",
172180
['FloatIndex', 'IntIndex',
173181
'StringIndex', 'UnicodeIndex',
174182
'DateIndex', 'PeriodIndex',
175-
'TimedeltaIndex'])
183+
'TimedeltaIndex', 'CategoricalIndex'])
176184
def test_to_xarray_index_types(self, index):
177-
tm._skip_if_no_xarray()
178185
from xarray import DataArray
179186

180187
index = getattr(tm, 'make{}'.format(index))
@@ -187,29 +194,6 @@ def test_to_xarray_index_types(self, index):
187194
assert_almost_equal(list(result.coords.keys()), ['foo'])
188195
assert isinstance(result, DataArray)
189196

190-
# idempotency
191-
assert_series_equal(result.to_series(), s,
192-
check_index_type=False)
193-
194-
@pytest.mark.xfail(reason="returning MultiIndex")
195-
def test_to_xarray_index_types_categorical(self):
196-
tm._skip_if_no_xarray()
197-
import xarray
198-
if LooseVersion(xarray.__version__) < '0.8.0':
199-
pytest.skip("xarray < 0.8.0 doesn't support categoricals")
200-
from xarray import DataArray
201-
202-
index = tm.makeCategoricalIndex
203-
204-
s = Series(range(6), index=index(6))
205-
s.index.name = 'foo'
206-
result = s.to_xarray()
207-
repr(result)
208-
assert len(result) == 6
209-
assert len(result.coords) == 1
210-
assert_almost_equal(list(result.coords.keys()), ['foo'])
211-
assert isinstance(result, DataArray)
212-
213197
# idempotency
214198
assert_series_equal(result.to_series(), s,
215199
check_index_type=False,

0 commit comments

Comments
 (0)