@@ -65,9 +65,8 @@ def test_assert_almost_equal_dicts(self):
65
65
self ._assert_almost_equal_both ({'a' : 1 , 'b' : 2 }, {'a' : 1 , 'b' : 2 })
66
66
67
67
self ._assert_not_almost_equal_both ({'a' : 1 , 'b' : 2 }, {'a' : 1 , 'b' : 3 })
68
- self ._assert_not_almost_equal_both (
69
- {'a' : 1 , 'b' : 2 }, {'a' : 1 , 'b' : 2 , 'c' : 3 }
70
- )
68
+ self ._assert_not_almost_equal_both ({'a' : 1 , 'b' : 2 },
69
+ {'a' : 1 , 'b' : 2 , 'c' : 3 })
71
70
self ._assert_not_almost_equal_both ({'a' : 1 }, 1 )
72
71
self ._assert_not_almost_equal_both ({'a' : 1 }, 'abc' )
73
72
self ._assert_not_almost_equal_both ({'a' : 1 }, [1 , ])
@@ -215,11 +214,11 @@ def test_numpy_array_equal_message(self):
215
214
\\ [right\\ ]: \\ [1\\ .0, nan, 3\\ .0\\ ]"""
216
215
217
216
with assertRaisesRegexp (AssertionError , expected ):
218
- assert_numpy_array_equal (
219
- np . array ([ np . nan , 2 , 3 ]), np .array ([1 , np .nan , 3 ]))
217
+ assert_numpy_array_equal (np . array ([ np . nan , 2 , 3 ]),
218
+ np .array ([1 , np .nan , 3 ]))
220
219
with assertRaisesRegexp (AssertionError , expected ):
221
- assert_almost_equal (
222
- np . array ([ np . nan , 2 , 3 ]), np .array ([1 , np .nan , 3 ]))
220
+ assert_almost_equal (np . array ([ np . nan , 2 , 3 ]),
221
+ np .array ([1 , np .nan , 3 ]))
223
222
224
223
expected = """numpy array are different
225
224
@@ -339,8 +338,8 @@ def test_index_equal_message(self):
339
338
labels=\\ [\\ [0, 0, 1, 1\\ ], \\ [0, 1, 2, 3\\ ]\\ ]\\ )"""
340
339
341
340
idx1 = pd .Index ([1 , 2 , 3 ])
342
- idx2 = pd .MultiIndex .from_tuples ([('A' , 1 ), ('A' , 2 ), ( 'B' , 3 ), ( 'B' , 4
343
- )])
341
+ idx2 = pd .MultiIndex .from_tuples ([('A' , 1 ), ('A' , 2 ),
342
+ ( 'B' , 3 ), ( 'B' , 4 )])
344
343
with assertRaisesRegexp (AssertionError , expected ):
345
344
assert_index_equal (idx1 , idx2 , exact = False )
346
345
@@ -350,10 +349,10 @@ def test_index_equal_message(self):
350
349
\\ [left\\ ]: Int64Index\\ (\\ [2, 2, 3, 4\\ ], dtype='int64'\\ )
351
350
\\ [right\\ ]: Int64Index\\ (\\ [1, 2, 3, 4\\ ], dtype='int64'\\ )"""
352
351
353
- idx1 = pd .MultiIndex .from_tuples ([('A' , 2 ), ('A' , 2 ), ( 'B' , 3 ), ( 'B' , 4
354
- )])
355
- idx2 = pd .MultiIndex .from_tuples ([('A' , 1 ), ('A' , 2 ), ( 'B' , 3 ), ( 'B' , 4
356
- )])
352
+ idx1 = pd .MultiIndex .from_tuples ([('A' , 2 ), ('A' , 2 ),
353
+ ( 'B' , 3 ), ( 'B' , 4 )])
354
+ idx2 = pd .MultiIndex .from_tuples ([('A' , 1 ), ('A' , 2 ),
355
+ ( 'B' , 3 ), ( 'B' , 4 )])
357
356
with assertRaisesRegexp (AssertionError , expected ):
358
357
assert_index_equal (idx1 , idx2 )
359
358
with assertRaisesRegexp (AssertionError , expected ):
@@ -434,10 +433,10 @@ def test_index_equal_message(self):
434
433
\\ [left\\ ]: Int64Index\\ (\\ [2, 2, 3, 4\\ ], dtype='int64'\\ )
435
434
\\ [right\\ ]: Int64Index\\ (\\ [1, 2, 3, 4\\ ], dtype='int64'\\ )"""
436
435
437
- idx1 = pd .MultiIndex .from_tuples ([('A' , 2 ), ('A' , 2 ), ( 'B' , 3 ), ( 'B' , 4
438
- )])
439
- idx2 = pd .MultiIndex .from_tuples ([('A' , 1 ), ('A' , 2 ), ( 'B' , 3 ), ( 'B' , 4
440
- )])
436
+ idx1 = pd .MultiIndex .from_tuples ([('A' , 2 ), ('A' , 2 ),
437
+ ( 'B' , 3 ), ( 'B' , 4 )])
438
+ idx2 = pd .MultiIndex .from_tuples ([('A' , 1 ), ('A' , 2 ),
439
+ ( 'B' , 3 ), ( 'B' , 4 )])
441
440
with assertRaisesRegexp (AssertionError , expected ):
442
441
assert_index_equal (idx1 , idx2 )
443
442
with assertRaisesRegexp (AssertionError , expected ):
@@ -674,6 +673,45 @@ def test_notisinstance(self):
674
673
tm .assertNotIsInstance (pd .Series ([1 ]), pd .Series )
675
674
676
675
676
+ class TestAssertCategoricalEqual (unittest .TestCase ):
677
+ _multiprocess_can_split_ = True
678
+
679
+ def test_categorical_equal_message (self ):
680
+
681
+ expected = """Categorical\\ .categories are different
682
+
683
+ Categorical\\ .categories values are different \\ (25\\ .0 %\\ )
684
+ \\ [left\\ ]: Int64Index\\ (\\ [1, 2, 3, 4\\ ], dtype='int64'\\ )
685
+ \\ [right\\ ]: Int64Index\\ (\\ [1, 2, 3, 5\\ ], dtype='int64'\\ )"""
686
+
687
+ a = pd .Categorical ([1 , 2 , 3 , 4 ])
688
+ b = pd .Categorical ([1 , 2 , 3 , 5 ])
689
+ with assertRaisesRegexp (AssertionError , expected ):
690
+ tm .assert_categorical_equal (a , b )
691
+
692
+ expected = """Categorical\\ .codes are different
693
+
694
+ Categorical\\ .codes values are different \\ (50\\ .0 %\\ )
695
+ \\ [left\\ ]: \\ [0, 1, 3, 2\\ ]
696
+ \\ [right\\ ]: \\ [0, 1, 2, 3\\ ]"""
697
+
698
+ a = pd .Categorical ([1 , 2 , 4 , 3 ], categories = [1 , 2 , 3 , 4 ])
699
+ b = pd .Categorical ([1 , 2 , 3 , 4 ], categories = [1 , 2 , 3 , 4 ])
700
+ with assertRaisesRegexp (AssertionError , expected ):
701
+ tm .assert_categorical_equal (a , b )
702
+
703
+ expected = """Categorical are different
704
+
705
+ Attribute "ordered" are different
706
+ \\ [left\\ ]: False
707
+ \\ [right\\ ]: True"""
708
+
709
+ a = pd .Categorical ([1 , 2 , 3 , 4 ], ordered = False )
710
+ b = pd .Categorical ([1 , 2 , 3 , 4 ], ordered = True )
711
+ with assertRaisesRegexp (AssertionError , expected ):
712
+ tm .assert_categorical_equal (a , b )
713
+
714
+
677
715
class TestRNGContext (unittest .TestCase ):
678
716
679
717
def test_RNGContext (self ):
0 commit comments