1
1
# -*- coding: utf-8 -*-
2
2
3
+ import pytest
4
+
3
5
import pandas .util .testing as tm
4
6
from pandas .core .indexes .api import Index , CategoricalIndex
5
7
from .common import Base
@@ -37,62 +39,66 @@ def test_construction(self):
37
39
38
40
result = Index (ci )
39
41
tm .assert_index_equal (result , ci , exact = True )
40
- self . assertFalse ( result .ordered )
42
+ assert not result .ordered
41
43
42
44
result = Index (ci .values )
43
45
tm .assert_index_equal (result , ci , exact = True )
44
- self . assertFalse ( result .ordered )
46
+ assert not result .ordered
45
47
46
48
# empty
47
49
result = CategoricalIndex (categories = categories )
48
- self .assert_index_equal (result .categories , Index (categories ))
50
+ tm .assert_index_equal (result .categories , Index (categories ))
49
51
tm .assert_numpy_array_equal (result .codes , np .array ([], dtype = 'int8' ))
50
- self . assertFalse ( result .ordered )
52
+ assert not result .ordered
51
53
52
54
# passing categories
53
55
result = CategoricalIndex (list ('aabbca' ), categories = categories )
54
- self .assert_index_equal (result .categories , Index (categories ))
56
+ tm .assert_index_equal (result .categories , Index (categories ))
55
57
tm .assert_numpy_array_equal (result .codes ,
56
- np .array ([0 , 0 , 1 , 1 , 2 , 0 ], dtype = 'int8' ))
58
+ np .array ([0 , 0 , 1 ,
59
+ 1 , 2 , 0 ], dtype = 'int8' ))
57
60
58
61
c = pd .Categorical (list ('aabbca' ))
59
62
result = CategoricalIndex (c )
60
- self .assert_index_equal (result .categories , Index (list ('abc' )))
63
+ tm .assert_index_equal (result .categories , Index (list ('abc' )))
61
64
tm .assert_numpy_array_equal (result .codes ,
62
- np .array ([0 , 0 , 1 , 1 , 2 , 0 ], dtype = 'int8' ))
63
- self .assertFalse (result .ordered )
65
+ np .array ([0 , 0 , 1 ,
66
+ 1 , 2 , 0 ], dtype = 'int8' ))
67
+ assert not result .ordered
64
68
65
69
result = CategoricalIndex (c , categories = categories )
66
- self .assert_index_equal (result .categories , Index (categories ))
70
+ tm .assert_index_equal (result .categories , Index (categories ))
67
71
tm .assert_numpy_array_equal (result .codes ,
68
- np .array ([0 , 0 , 1 , 1 , 2 , 0 ], dtype = 'int8' ))
69
- self .assertFalse (result .ordered )
72
+ np .array ([0 , 0 , 1 ,
73
+ 1 , 2 , 0 ], dtype = 'int8' ))
74
+ assert not result .ordered
70
75
71
76
ci = CategoricalIndex (c , categories = list ('abcd' ))
72
77
result = CategoricalIndex (ci )
73
- self .assert_index_equal (result .categories , Index (categories ))
78
+ tm .assert_index_equal (result .categories , Index (categories ))
74
79
tm .assert_numpy_array_equal (result .codes ,
75
- np .array ([0 , 0 , 1 , 1 , 2 , 0 ], dtype = 'int8' ))
76
- self .assertFalse (result .ordered )
80
+ np .array ([0 , 0 , 1 ,
81
+ 1 , 2 , 0 ], dtype = 'int8' ))
82
+ assert not result .ordered
77
83
78
84
result = CategoricalIndex (ci , categories = list ('ab' ))
79
- self .assert_index_equal (result .categories , Index (list ('ab' )))
85
+ tm .assert_index_equal (result .categories , Index (list ('ab' )))
80
86
tm .assert_numpy_array_equal (result .codes ,
81
- np .array ([0 , 0 , 1 , 1 , - 1 , 0 ],
82
- dtype = 'int8' ))
83
- self . assertFalse ( result .ordered )
87
+ np .array ([0 , 0 , 1 ,
88
+ 1 , - 1 , 0 ], dtype = 'int8' ))
89
+ assert not result .ordered
84
90
85
91
result = CategoricalIndex (ci , categories = list ('ab' ), ordered = True )
86
- self .assert_index_equal (result .categories , Index (list ('ab' )))
92
+ tm .assert_index_equal (result .categories , Index (list ('ab' )))
87
93
tm .assert_numpy_array_equal (result .codes ,
88
- np .array ([0 , 0 , 1 , 1 , - 1 , 0 ],
89
- dtype = 'int8' ))
90
- self . assertTrue ( result .ordered )
94
+ np .array ([0 , 0 , 1 ,
95
+ 1 , - 1 , 0 ], dtype = 'int8' ))
96
+ assert result .ordered
91
97
92
98
# turn me to an Index
93
99
result = Index (np .array (ci ))
94
- self . assertIsInstance (result , Index )
95
- self . assertNotIsInstance (result , CategoricalIndex )
100
+ assert isinstance (result , Index )
101
+ assert not isinstance (result , CategoricalIndex )
96
102
97
103
def test_construction_with_dtype (self ):
98
104
@@ -325,9 +331,9 @@ def test_delete(self):
325
331
expected = CategoricalIndex (list ('aabbc' ), categories = categories )
326
332
tm .assert_index_equal (result , expected , exact = True )
327
333
328
- with tm . assertRaises ((IndexError , ValueError )):
329
- # either depeidnig on numpy version
330
- result = ci .delete (10 )
334
+ with pytest . raises ((IndexError , ValueError )):
335
+ # Either depending on NumPy version
336
+ ci .delete (10 )
331
337
332
338
def test_astype (self ):
333
339
@@ -336,12 +342,12 @@ def test_astype(self):
336
342
tm .assert_index_equal (result , ci , exact = True )
337
343
338
344
result = ci .astype (object )
339
- self .assert_index_equal (result , Index (np .array (ci )))
345
+ tm .assert_index_equal (result , Index (np .array (ci )))
340
346
341
347
# this IS equal, but not the same class
342
- self . assertTrue ( result .equals (ci ) )
343
- self . assertIsInstance (result , Index )
344
- self . assertNotIsInstance (result , CategoricalIndex )
348
+ assert result .equals (ci )
349
+ assert isinstance (result , Index )
350
+ assert not isinstance (result , CategoricalIndex )
345
351
346
352
# interval
347
353
ii = IntervalIndex .from_arrays (left = [- 0.001 , 2.0 ],
0 commit comments