@@ -177,12 +177,17 @@ def test_constructor_ndarray_like(self):
177
177
# it should be possible to convert any object that satisfies the numpy
178
178
# ndarray interface directly into an Index
179
179
class ArrayLike (object ):
180
+ def __init__ (self , array ):
181
+ self .array = array
180
182
def __array__ (self , dtype = None ):
181
- return np . arange ( 5 )
183
+ return self . array
182
184
183
- expected = pd .Index (np .arange (5 ))
184
- result = pd .Index (ArrayLike ())
185
- self .assertTrue (result .equals (expected ))
185
+ for array in [np .arange (5 ),
186
+ np .array (['a' , 'b' , 'c' ]),
187
+ pd .date_range ('2000-01-01' , periods = 3 ).values ]:
188
+ expected = pd .Index (array )
189
+ result = pd .Index (ArrayLike (array ))
190
+ self .assertTrue (result .equals (expected ))
186
191
187
192
def test_index_ctor_infer_periodindex (self ):
188
193
from pandas import period_range , PeriodIndex
@@ -447,7 +452,7 @@ def test_intersection(self):
447
452
assertRaisesRegexp (TypeError , "iterable" , first .intersection , 0.5 )
448
453
449
454
idx1 = Index ([1 , 2 , 3 , 4 , 5 ], name = 'idx' )
450
- # if target has the same name, it is preserved
455
+ # if target has the same name, it is preserved
451
456
idx2 = Index ([3 , 4 , 5 , 6 , 7 ], name = 'idx' )
452
457
expected2 = Index ([3 , 4 , 5 ], name = 'idx' )
453
458
result2 = idx1 .intersection (idx2 )
0 commit comments