Skip to content

Commit 1c37523

Browse files
dsm054jreback
authored andcommitted
TST: Verify that float columns stay float after pivot (pandas-dev#7142) (pandas-dev#16815)
1 parent 7d0a98e commit 1c37523

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: pandas/tests/reshape/test_pivot.py

+18
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,24 @@ def test_pivot_dtypes(self):
167167
expected = Series(dict(float64=2))
168168
tm.assert_series_equal(result, expected)
169169

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+
170188
def test_pivot_no_values(self):
171189
# GH 14380
172190
idx = pd.DatetimeIndex(['2011-01-01', '2011-02-01', '2011-01-02',

0 commit comments

Comments
 (0)