diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index fc5a2eb468d4fd..68726fdf4b7614 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -167,6 +167,21 @@ def test_pivot_dtypes(self): expected = Series(dict(float64=2)) tm.assert_series_equal(result, expected) + def test_pivot_preserve_dtypes(): + # GH 7172 regression test + v = np.arange(5, dtype=np.float64) + df = DataFrame({'f1': v, 'f2': v + 2.0, + 'b1': v <= 2, 'b2': v <= 3}).reset_index() + + values_cols = [['f1', 'f2'], ['f1', 'f2', 'b2']] + for values in values_cols: + df_res = df.pivot_table(index='index', columns='b1', + values=values) + result = dict(df_res.dtypes) + expected = {col: np.dtype('O') if col[0].startswith('b') + else np.dtype('float64') for col in df_res} + assert result == expected + def test_pivot_no_values(self): # GH 14380 idx = pd.DatetimeIndex(['2011-01-01', '2011-02-01', '2011-01-02',