@@ -167,6 +167,24 @@ def test_pivot_dtypes(self):
167
167
expected = Series (dict (float64 = 2 ))
168
168
tm .assert_series_equal (result , expected )
169
169
170
+ @pytest .mark .parametrize ('columns,values' ,
171
+ [('bool1' , ['float1' , 'float2' ]),
172
+ ('bool1' , ['float1' , 'float2' , 'bool1' ]),
173
+ ('bool2' , ['float1' , 'float2' , 'bool1' ])])
174
+ def test_pivot_preserve_dtypes (self , columns , values ):
175
+ # GH 7142 regression test
176
+ v = np .arange (5 , dtype = np .float64 )
177
+ df = DataFrame ({'float1' : v , 'float2' : v + 2.0 ,
178
+ 'bool1' : v <= 2 , 'bool2' : v <= 3 })
179
+
180
+ df_res = df .reset_index ().pivot_table (
181
+ index = 'index' , columns = columns , values = values )
182
+
183
+ result = dict (df_res .dtypes )
184
+ expected = {col : np .dtype ('O' ) if col [0 ].startswith ('b' )
185
+ else np .dtype ('float64' ) for col in df_res }
186
+ assert result == expected
187
+
170
188
def test_pivot_no_values (self ):
171
189
# GH 14380
172
190
idx = pd .DatetimeIndex (['2011-01-01' , '2011-02-01' , '2011-01-02' ,
0 commit comments