@@ -129,6 +129,39 @@ def test_align_mixed_int(self, mixed_int_frame):
129
129
)
130
130
tm .assert_index_equal (bf .index , Index ([]))
131
131
132
+ @pytest .mark .parametrize (
133
+ "l_ordered,r_ordered,expected" ,
134
+ [
135
+ [True , True , pd .CategoricalIndex ],
136
+ [True , False , pd .Index ],
137
+ [False , True , pd .Index ],
138
+ [False , False , pd .CategoricalIndex ],
139
+ ],
140
+ )
141
+ def test_align_categorical (self , l_ordered , r_ordered , expected ):
142
+ # GH-28397
143
+ df_1 = DataFrame (
144
+ {
145
+ "A" : np .arange (6 , dtype = "int64" ),
146
+ "B" : Series (list ("aabbca" )).astype (
147
+ pd .CategoricalDtype (list ("cab" ), ordered = l_ordered )
148
+ ),
149
+ }
150
+ ).set_index ("B" )
151
+ df_2 = DataFrame (
152
+ {
153
+ "A" : np .arange (5 , dtype = "int64" ),
154
+ "B" : Series (list ("babca" )).astype (
155
+ pd .CategoricalDtype (list ("cab" ), ordered = r_ordered )
156
+ ),
157
+ }
158
+ ).set_index ("B" )
159
+
160
+ aligned_1 , aligned_2 = df_1 .align (df_2 )
161
+ assert isinstance (aligned_1 .index , expected )
162
+ assert isinstance (aligned_2 .index , expected )
163
+ tm .assert_index_equal (aligned_1 .index , aligned_2 .index )
164
+
132
165
def test_align_multiindex (self ):
133
166
# GH#10665
134
167
# same test cases as test_align_multiindex in test_series.py
0 commit comments