@@ -2810,6 +2810,63 @@ def test_to_string_multindex_header(self):
2810
2810
assert res == exp
2811
2811
2812
2812
2813
+ class TestGenericArrayFormatter :
2814
+ def test_1d_array (self ):
2815
+ # GenericArrayFormatter is used on types for which there isn't a dedicated
2816
+ # formatter. np.bool is one of those types.
2817
+ obj = fmt .GenericArrayFormatter (np .array ([True , False ]))
2818
+ res = obj .get_result ()
2819
+ assert len (res ) == 2
2820
+ # Results should be right-justified.
2821
+ assert res [0 ] == " True"
2822
+ assert res [1 ] == " False"
2823
+
2824
+ def test_2d_array (self ):
2825
+ obj = fmt .GenericArrayFormatter (np .array ([[True , False ], [False , True ]]))
2826
+ res = obj .get_result ()
2827
+ assert len (res ) == 2
2828
+ assert res [0 ] == " [True, False]"
2829
+ assert res [1 ] == " [False, True]"
2830
+
2831
+ def test_3d_array (self ):
2832
+ obj = fmt .GenericArrayFormatter (
2833
+ np .array ([[[True , True ], [False , False ]], [[False , True ], [True , False ]]])
2834
+ )
2835
+ res = obj .get_result ()
2836
+ assert len (res ) == 2
2837
+ assert res [0 ] == " [[True, True], [False, False]]"
2838
+ assert res [1 ] == " [[False, True], [True, False]]"
2839
+
2840
+ def test_2d_extension_type (self ):
2841
+ # GH 33770
2842
+
2843
+ # Define a stub extension type with just enough code to run Series.__repr__()
2844
+ class DtypeStub (pd .api .extensions .ExtensionDtype ):
2845
+ @property
2846
+ def type (self ):
2847
+ return np .ndarray
2848
+
2849
+ @property
2850
+ def name (self ):
2851
+ return "DtypeStub"
2852
+
2853
+ class ExtTypeStub (pd .api .extensions .ExtensionArray ):
2854
+ def __len__ (self ):
2855
+ return 2
2856
+
2857
+ def __getitem__ (self , ix ):
2858
+ return [ix == 1 , ix == 0 ]
2859
+
2860
+ @property
2861
+ def dtype (self ):
2862
+ return DtypeStub ()
2863
+
2864
+ series = pd .Series (ExtTypeStub ())
2865
+ res = repr (series ) # This line crashed before #33770 was fixed.
2866
+ expected = "0 [False True]\n " + "1 [ True False]\n " + "dtype: DtypeStub"
2867
+ assert res == expected
2868
+
2869
+
2813
2870
def _three_digit_exp ():
2814
2871
return f"{ 1.7e8 :.4g} " == "1.7e+008"
2815
2872
0 commit comments