1717import pandas .util .testing as tm
1818from .test_generic import Generic
1919
20+ try :
21+ import xarray
22+ _XARRAY_INSTALLED = True
23+ except ImportError :
24+ _XARRAY_INSTALLED = False
25+
2026
2127class 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