17
17
import pandas .util .testing as tm
18
18
from .test_generic import Generic
19
19
20
+ try :
21
+ import xarray
22
+ _XARRAY_INSTALLED = True
23
+ except ImportError :
24
+ _XARRAY_INSTALLED = False
25
+
20
26
21
27
class TestSeries (Generic ):
22
28
_typ = Series
@@ -166,15 +172,16 @@ def finalize(self, other, method=None, **kwargs):
166
172
Series ._metadata = _metadata
167
173
Series .__finalize__ = _finalize
168
174
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' )
170
178
@pytest .mark .parametrize (
171
179
"index" ,
172
180
['FloatIndex' , 'IntIndex' ,
173
181
'StringIndex' , 'UnicodeIndex' ,
174
182
'DateIndex' , 'PeriodIndex' ,
175
- 'TimedeltaIndex' ])
183
+ 'TimedeltaIndex' , 'CategoricalIndex' ])
176
184
def test_to_xarray_index_types (self , index ):
177
- tm ._skip_if_no_xarray ()
178
185
from xarray import DataArray
179
186
180
187
index = getattr (tm , 'make{}' .format (index ))
@@ -187,29 +194,6 @@ def test_to_xarray_index_types(self, index):
187
194
assert_almost_equal (list (result .coords .keys ()), ['foo' ])
188
195
assert isinstance (result , DataArray )
189
196
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
-
213
197
# idempotency
214
198
assert_series_equal (result .to_series (), s ,
215
199
check_index_type = False ,
0 commit comments