We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 329fdaa commit 9ba6a6dCopy full SHA for 9ba6a6d
pandas/tests/reshape/test_pivot.py
@@ -167,6 +167,24 @@ def test_pivot_dtypes(self):
167
expected = Series(dict(float64=2))
168
tm.assert_series_equal(result, expected)
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
188
def test_pivot_no_values(self):
189
# GH 14380
190
idx = pd.DatetimeIndex(['2011-01-01', '2011-02-01', '2011-01-02',
0 commit comments