Skip to content

Commit 151c40c

Browse files
author
tp
committed
moved tests from TestAnnual to TestPivotTable
1 parent 9310f0f commit 151c40c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

pandas/tests/reshape/test_pivot.py

+34
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,40 @@ def test_pivot_dtaccessor(self):
890890
index=['X', 'Y'], columns=exp_col)
891891
tm.assert_frame_equal(result, expected)
892892

893+
def test_daily(self):
894+
rng = date_range('1/1/2000', '12/31/2004', freq='D')
895+
ts = Series(np.random.randn(len(rng)), index=rng)
896+
897+
annual = pivot_table(DataFrame(ts), index=ts.index.year,
898+
columns=ts.index.dayofyear)
899+
annual.columns = annual.columns.droplevel(0)
900+
901+
doy = np.asarray(ts.index.dayofyear)
902+
903+
for i in range(1, 367):
904+
subset = ts[doy == i]
905+
subset.index = subset.index.year
906+
907+
result = annual[i].dropna()
908+
tm.assert_series_equal(result, subset, check_names=False)
909+
assert result.name == i
910+
911+
def test_monthly(self):
912+
rng = date_range('1/1/2000', '12/31/2004', freq='M')
913+
ts = Series(np.random.randn(len(rng)), index=rng)
914+
915+
annual = pivot_table(pd.DataFrame(ts), index=ts.index.year,
916+
columns=ts.index.month)
917+
annual.columns = annual.columns.droplevel(0)
918+
919+
month = ts.index.month
920+
for i in range(1, 13):
921+
subset = ts[month == i]
922+
subset.index = subset.index.year
923+
result = annual[i].dropna()
924+
tm.assert_series_equal(result, subset, check_names=False)
925+
assert result.name == i
926+
893927
def test_pivot_table_with_iterator_values(self):
894928
# GH 12017
895929
aggs = {'D': 'sum', 'E': 'mean'}

0 commit comments

Comments
 (0)