Skip to content

Commit

Permalink
TST: Verify that float columns stay float after pivot (#7142) (#16815)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsm054 authored and jreback committed Jul 6, 2017
1 parent 7d0a98e commit 1c37523
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pandas/tests/reshape/test_pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,24 @@ def test_pivot_dtypes(self):
expected = Series(dict(float64=2))
tm.assert_series_equal(result, expected)

@pytest.mark.parametrize('columns,values',
[('bool1', ['float1', 'float2']),
('bool1', ['float1', 'float2', 'bool1']),
('bool2', ['float1', 'float2', 'bool1'])])
def test_pivot_preserve_dtypes(self, columns, values):
# GH 7142 regression test
v = np.arange(5, dtype=np.float64)
df = DataFrame({'float1': v, 'float2': v + 2.0,
'bool1': v <= 2, 'bool2': v <= 3})

df_res = df.reset_index().pivot_table(
index='index', columns=columns, 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 1c37523

Please sign in to comment.