Skip to content

Commit

Permalink
TST: Verify that float columns stay float after pivot (#7142)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsm054 committed Jul 3, 2017
1 parent 329fdaa commit 0eeec92
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(self):
# GH 7142 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',
Expand Down

0 comments on commit 0eeec92

Please sign in to comment.