11# -*- coding: utf-8 -*-
22
3+ import pytest
4+
35import pandas .util .testing as tm
46from pandas .core .indexes .api import Index , CategoricalIndex
57from .common import Base
@@ -37,62 +39,66 @@ def test_construction(self):
3739
3840 result = Index (ci )
3941 tm .assert_index_equal (result , ci , exact = True )
40- self . assertFalse ( result .ordered )
42+ assert not result .ordered
4143
4244 result = Index (ci .values )
4345 tm .assert_index_equal (result , ci , exact = True )
44- self . assertFalse ( result .ordered )
46+ assert not result .ordered
4547
4648 # empty
4749 result = CategoricalIndex (categories = categories )
48- self .assert_index_equal (result .categories , Index (categories ))
50+ tm .assert_index_equal (result .categories , Index (categories ))
4951 tm .assert_numpy_array_equal (result .codes , np .array ([], dtype = 'int8' ))
50- self . assertFalse ( result .ordered )
52+ assert not result .ordered
5153
5254 # passing categories
5355 result = CategoricalIndex (list ('aabbca' ), categories = categories )
54- self .assert_index_equal (result .categories , Index (categories ))
56+ tm .assert_index_equal (result .categories , Index (categories ))
5557 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' ))
5760
5861 c = pd .Categorical (list ('aabbca' ))
5962 result = CategoricalIndex (c )
60- self .assert_index_equal (result .categories , Index (list ('abc' )))
63+ tm .assert_index_equal (result .categories , Index (list ('abc' )))
6164 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
6468
6569 result = CategoricalIndex (c , categories = categories )
66- self .assert_index_equal (result .categories , Index (categories ))
70+ tm .assert_index_equal (result .categories , Index (categories ))
6771 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
7075
7176 ci = CategoricalIndex (c , categories = list ('abcd' ))
7277 result = CategoricalIndex (ci )
73- self .assert_index_equal (result .categories , Index (categories ))
78+ tm .assert_index_equal (result .categories , Index (categories ))
7479 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
7783
7884 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' )))
8086 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
8490
8591 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' )))
8793 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
9197
9298 # turn me to an Index
9399 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 )
96102
97103 def test_construction_with_dtype (self ):
98104
@@ -325,9 +331,9 @@ def test_delete(self):
325331 expected = CategoricalIndex (list ('aabbc' ), categories = categories )
326332 tm .assert_index_equal (result , expected , exact = True )
327333
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 )
331337
332338 def test_astype (self ):
333339
@@ -336,12 +342,12 @@ def test_astype(self):
336342 tm .assert_index_equal (result , ci , exact = True )
337343
338344 result = ci .astype (object )
339- self .assert_index_equal (result , Index (np .array (ci )))
345+ tm .assert_index_equal (result , Index (np .array (ci )))
340346
341347 # 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 )
345351
346352 # interval
347353 ii = IntervalIndex .from_arrays (left = [- 0.001 , 2.0 ],
0 commit comments