|
26 | 26 | from pandas.compat import range, lrange, StringIO, lrange
|
27 | 27 | from pandas import compat
|
28 | 28 | from pandas.tools.util import cartesian_product
|
| 29 | +from pandas.tools.pivot import pivot_table |
29 | 30 |
|
30 | 31 | import pandas.sparse.frame as spf
|
31 | 32 |
|
@@ -1449,7 +1450,7 @@ def test_apply_nonuq(self):
|
1449 | 1450 | [[1, 2, 3], [4, 5, 6], [7, 8, 9]], index=['a', 'a', 'c'])
|
1450 | 1451 | df = df_orig.to_sparse()
|
1451 | 1452 | rs = df.apply(lambda s: s[0], axis=1)
|
1452 |
| - xp = Series([1, 4, 7], ['a', 'a', 'c']) |
| 1453 | + xp = Series([1, 4, 7], ['a', 'a', 'c'])#.astype(float) |
1453 | 1454 | assert_series_equal(rs, xp)
|
1454 | 1455 |
|
1455 | 1456 | # df.T breaks
|
@@ -1719,6 +1720,18 @@ def test_nan_columnname(self):
|
1719 | 1720 | nan_colname_sparse = nan_colname.to_sparse()
|
1720 | 1721 | self.assertTrue(np.isnan(nan_colname_sparse.columns[0]))
|
1721 | 1722 |
|
| 1723 | + def test_pivot(self): |
| 1724 | + # issue #11856 |
| 1725 | + df = DataFrame( list(zip([3,2,4,1,5,3,2], |
| 1726 | + ["chr1", "chr1", "chr1", "chr1", "chr2", "chr2", "chr3"], |
| 1727 | + [100,100, 100, 200, 1, 3, 1], |
| 1728 | + [True, True, True, False, True, False, True], |
| 1729 | + [-1,0,1,3, 0,2,1])) , |
| 1730 | + columns = ["counts", "chr", "pos", "strand", "distance"]) |
| 1731 | + |
| 1732 | + dfpiv_from_sparse = pivot_table(SparseDataFrame(df), index= [ "chr", "pos"], columns= ["strand","distance"], values= "counts").fillna(0) |
| 1733 | + dfpiv = pivot_table(df, index= [ "chr", "pos"], columns= ["strand","distance"], values= "counts").fillna(0) |
| 1734 | + assert_frame_equal(dfpiv, dfpiv0) |
1722 | 1735 |
|
1723 | 1736 | def _dense_series_compare(s, f):
|
1724 | 1737 | result = f(s)
|
|
0 commit comments