Skip to content

Commit 4f7f84f

Browse files
committed
TST: Verify that float columns stay float after pivot (pandas-dev#7142)
1 parent 329fdaa commit 4f7f84f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pandas/tests/reshape/test_pivot.py

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

170+
def test_pivot_preserve_dtypes():
171+
# GH 7142 regression test
172+
v = np.arange(5, dtype=np.float64)
173+
df = DataFrame({'f1': v, 'f2': v + 2.0,
174+
'b1': v <= 2, 'b2': v <= 3}).reset_index()
175+
176+
values_cols = [['f1', 'f2'], ['f1', 'f2', 'b2']]
177+
for values in values_cols:
178+
df_res = df.pivot_table(index='index', columns='b1',
179+
values=values)
180+
result = dict(df_res.dtypes)
181+
expected = {col: np.dtype('O') if col[0].startswith('b')
182+
else np.dtype('float64') for col in df_res}
183+
assert result == expected
184+
170185
def test_pivot_no_values(self):
171186
# GH 14380
172187
idx = pd.DatetimeIndex(['2011-01-01', '2011-02-01', '2011-01-02',

0 commit comments

Comments
 (0)