@@ -65,9 +65,8 @@ def test_assert_almost_equal_dicts(self):
6565 self ._assert_almost_equal_both ({'a' : 1 , 'b' : 2 }, {'a' : 1 , 'b' : 2 })
6666
6767 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 })
7170 self ._assert_not_almost_equal_both ({'a' : 1 }, 1 )
7271 self ._assert_not_almost_equal_both ({'a' : 1 }, 'abc' )
7372 self ._assert_not_almost_equal_both ({'a' : 1 }, [1 , ])
@@ -215,11 +214,11 @@ def test_numpy_array_equal_message(self):
215214\\ [right\\ ]: \\ [1\\ .0, nan, 3\\ .0\\ ]"""
216215
217216 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 ]))
220219 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 ]))
223222
224223 expected = """numpy array are different
225224
@@ -339,8 +338,8 @@ def test_index_equal_message(self):
339338 labels=\\ [\\ [0, 0, 1, 1\\ ], \\ [0, 1, 2, 3\\ ]\\ ]\\ )"""
340339
341340 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 )])
344343 with assertRaisesRegexp (AssertionError , expected ):
345344 assert_index_equal (idx1 , idx2 , exact = False )
346345
@@ -350,10 +349,10 @@ def test_index_equal_message(self):
350349\\ [left\\ ]: Int64Index\\ (\\ [2, 2, 3, 4\\ ], dtype='int64'\\ )
351350\\ [right\\ ]: Int64Index\\ (\\ [1, 2, 3, 4\\ ], dtype='int64'\\ )"""
352351
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 )])
357356 with assertRaisesRegexp (AssertionError , expected ):
358357 assert_index_equal (idx1 , idx2 )
359358 with assertRaisesRegexp (AssertionError , expected ):
@@ -434,10 +433,10 @@ def test_index_equal_message(self):
434433\\ [left\\ ]: Int64Index\\ (\\ [2, 2, 3, 4\\ ], dtype='int64'\\ )
435434\\ [right\\ ]: Int64Index\\ (\\ [1, 2, 3, 4\\ ], dtype='int64'\\ )"""
436435
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 )])
441440 with assertRaisesRegexp (AssertionError , expected ):
442441 assert_index_equal (idx1 , idx2 )
443442 with assertRaisesRegexp (AssertionError , expected ):
@@ -674,6 +673,45 @@ def test_notisinstance(self):
674673 tm .assertNotIsInstance (pd .Series ([1 ]), pd .Series )
675674
676675
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+
677715class TestRNGContext (unittest .TestCase ):
678716
679717 def test_RNGContext (self ):
0 commit comments