@@ -3279,3 +3279,78 @@ def test_duplicate_multiindex_labels(self):
32793279 with pytest .raises (ValueError ):
32803280 ind .set_levels ([['A' , 'B' , 'A' , 'A' , 'B' ], [2 , 1 , 3 , - 2 , 5 ]],
32813281 inplace = True )
3282+
3283+ def test_repr (self ):
3284+ # GH21145
3285+
3286+ # no items
3287+ idx1 , idx2 = range (0 ), []
3288+ idx = pd .MultiIndex .from_arrays ([idx1 , idx2 ])
3289+ expected = """\
3290+ MultiIndex(levels=[[], []],
3291+ labels=[[], []])"""
3292+ assert repr (idx ) == expected
3293+
3294+ # two items
3295+ idx1 , idx2 = range (2 ), ['a' , 'b' ]
3296+ idx = MultiIndex .from_arrays ([idx1 , idx2 ])
3297+ expected = """\
3298+ MultiIndex(levels=[[0, 1], ['a', 'b']],
3299+ labels=[[0, 1], [0, 1]])"""
3300+ assert repr (idx ) == expected
3301+
3302+ # 100 items
3303+ idx1 , idx2 = range (100 ), range (100 )
3304+ idx = pd .MultiIndex .from_arrays ([idx1 , idx2 ])
3305+ expected = """\
3306+ MultiIndex(levels=[[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
3307+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
3308+ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
3309+ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
3310+ 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
3311+ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
3312+ 90, 91, 92, 93, 94, 95, 96, 97, 98, 99],
3313+ [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
3314+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
3315+ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
3316+ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
3317+ 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
3318+ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
3319+ 90, 91, 92, 93, 94, 95, 96, 97, 98, 99],
3320+ ],
3321+ labels=[[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
3322+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
3323+ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
3324+ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
3325+ 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
3326+ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
3327+ 90, 91, 92, 93, 94, 95, 96, 97, 98, 99],
3328+ [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
3329+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
3330+ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
3331+ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
3332+ 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
3333+ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
3334+ 90, 91, 92, 93, 94, 95, 96, 97, 98, 99],
3335+ ])"""
3336+ assert repr (idx ) == expected
3337+
3338+ # 1000 items
3339+ idx1 , idx2 = range (1000 ), range (1000 )
3340+ idx = pd .MultiIndex .from_arrays ([idx1 , idx2 ])
3341+ expected = """\
3342+ MultiIndex(levels=[[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
3343+ ...
3344+ 990, 991, 992, 993, 994, 995, 996, 997, 998, 999],
3345+ [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
3346+ ...
3347+ 990, 991, 992, 993, 994, 995, 996, 997, 998, 999],
3348+ ],
3349+ labels=[[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
3350+ ...
3351+ 990, 991, 992, 993, 994, 995, 996, 997, 998, 999],
3352+ [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
3353+ ...
3354+ 990, 991, 992, 993, 994, 995, 996, 997, 998, 999],
3355+ ])"""
3356+ assert repr (idx ) == expected
0 commit comments