|
13 | 13 | from pandas.core.reshape.pivot import pivot_table, crosstab
|
14 | 14 | from pandas.compat import range, product
|
15 | 15 | import pandas.util.testing as tm
|
16 |
| -from pandas.tseries.util import pivot_annual, isleapyear |
17 | 16 | from pandas.api.types import CategoricalDtype as CDT
|
18 | 17 |
|
19 | 18 |
|
@@ -1048,6 +1047,16 @@ def test_pivot_table_not_series(self):
|
1048 | 1047 |
|
1049 | 1048 | tm.assert_frame_equal(result, expected)
|
1050 | 1049 |
|
| 1050 | + def test_pivot_margins_name_unicode(self): |
| 1051 | + # issue #13292 |
| 1052 | + greek = u'\u0394\u03bf\u03ba\u03b9\u03bc\u03ae' |
| 1053 | + frame = pd.DataFrame({'foo': [1, 2, 3]}) |
| 1054 | + table = pd.pivot_table(frame, index=['foo'], aggfunc=len, margins=True, |
| 1055 | + margins_name=greek) |
| 1056 | + index = pd.Index([1, 2, 3, greek], dtype='object', name='foo') |
| 1057 | + expected = pd.DataFrame(index=index) |
| 1058 | + tm.assert_frame_equal(table, expected) |
| 1059 | + |
1051 | 1060 |
|
1052 | 1061 | class TestCrosstab(object):
|
1053 | 1062 |
|
@@ -1525,116 +1534,3 @@ def test_crosstab_dup_index_names(self):
|
1525 | 1534 | index=expected_index,
|
1526 | 1535 | columns=expected_index)
|
1527 | 1536 | tm.assert_frame_equal(result, expected)
|
1528 |
| - |
1529 |
| - |
1530 |
| -class TestPivotAnnual(object): |
1531 |
| - """ |
1532 |
| - New pandas of scikits.timeseries pivot_annual |
1533 |
| - """ |
1534 |
| - |
1535 |
| - def test_daily(self): |
1536 |
| - rng = date_range('1/1/2000', '12/31/2004', freq='D') |
1537 |
| - ts = Series(np.random.randn(len(rng)), index=rng) |
1538 |
| - |
1539 |
| - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): |
1540 |
| - annual = pivot_annual(ts, 'D') |
1541 |
| - |
1542 |
| - doy = np.asarray(ts.index.dayofyear) |
1543 |
| - |
1544 |
| - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): |
1545 |
| - doy[(~isleapyear(ts.index.year)) & (doy >= 60)] += 1 |
1546 |
| - |
1547 |
| - for i in range(1, 367): |
1548 |
| - subset = ts[doy == i] |
1549 |
| - subset.index = [x.year for x in subset.index] |
1550 |
| - |
1551 |
| - result = annual[i].dropna() |
1552 |
| - tm.assert_series_equal(result, subset, check_names=False) |
1553 |
| - assert result.name == i |
1554 |
| - |
1555 |
| - # check leap days |
1556 |
| - leaps = ts[(ts.index.month == 2) & (ts.index.day == 29)] |
1557 |
| - day = leaps.index.dayofyear[0] |
1558 |
| - leaps.index = leaps.index.year |
1559 |
| - leaps.name = 60 |
1560 |
| - tm.assert_series_equal(annual[day].dropna(), leaps) |
1561 |
| - |
1562 |
| - def test_hourly(self): |
1563 |
| - rng_hourly = date_range('1/1/1994', periods=(18 * 8760 + 4 * 24), |
1564 |
| - freq='H') |
1565 |
| - data_hourly = np.random.randint(100, 350, rng_hourly.size) |
1566 |
| - ts_hourly = Series(data_hourly, index=rng_hourly) |
1567 |
| - |
1568 |
| - grouped = ts_hourly.groupby(ts_hourly.index.year) |
1569 |
| - hoy = grouped.apply(lambda x: x.reset_index(drop=True)) |
1570 |
| - hoy = hoy.index.droplevel(0).values |
1571 |
| - |
1572 |
| - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): |
1573 |
| - hoy[~isleapyear(ts_hourly.index.year) & (hoy >= 1416)] += 24 |
1574 |
| - hoy += 1 |
1575 |
| - |
1576 |
| - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): |
1577 |
| - annual = pivot_annual(ts_hourly) |
1578 |
| - |
1579 |
| - ts_hourly = ts_hourly.astype(float) |
1580 |
| - for i in [1, 1416, 1417, 1418, 1439, 1440, 1441, 8784]: |
1581 |
| - subset = ts_hourly[hoy == i] |
1582 |
| - subset.index = [x.year for x in subset.index] |
1583 |
| - |
1584 |
| - result = annual[i].dropna() |
1585 |
| - tm.assert_series_equal(result, subset, check_names=False) |
1586 |
| - assert result.name == i |
1587 |
| - |
1588 |
| - leaps = ts_hourly[(ts_hourly.index.month == 2) & ( |
1589 |
| - ts_hourly.index.day == 29) & (ts_hourly.index.hour == 0)] |
1590 |
| - hour = leaps.index.dayofyear[0] * 24 - 23 |
1591 |
| - leaps.index = leaps.index.year |
1592 |
| - leaps.name = 1417 |
1593 |
| - tm.assert_series_equal(annual[hour].dropna(), leaps) |
1594 |
| - |
1595 |
| - def test_weekly(self): |
1596 |
| - pass |
1597 |
| - |
1598 |
| - def test_monthly(self): |
1599 |
| - rng = date_range('1/1/2000', '12/31/2004', freq='M') |
1600 |
| - ts = Series(np.random.randn(len(rng)), index=rng) |
1601 |
| - |
1602 |
| - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): |
1603 |
| - annual = pivot_annual(ts, 'M') |
1604 |
| - |
1605 |
| - month = ts.index.month |
1606 |
| - for i in range(1, 13): |
1607 |
| - subset = ts[month == i] |
1608 |
| - subset.index = [x.year for x in subset.index] |
1609 |
| - result = annual[i].dropna() |
1610 |
| - tm.assert_series_equal(result, subset, check_names=False) |
1611 |
| - assert result.name == i |
1612 |
| - |
1613 |
| - def test_period_monthly(self): |
1614 |
| - pass |
1615 |
| - |
1616 |
| - def test_period_daily(self): |
1617 |
| - pass |
1618 |
| - |
1619 |
| - def test_period_weekly(self): |
1620 |
| - pass |
1621 |
| - |
1622 |
| - def test_isleapyear_deprecate(self): |
1623 |
| - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): |
1624 |
| - assert isleapyear(2000) |
1625 |
| - |
1626 |
| - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): |
1627 |
| - assert not isleapyear(2001) |
1628 |
| - |
1629 |
| - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): |
1630 |
| - assert isleapyear(2004) |
1631 |
| - |
1632 |
| - def test_pivot_margins_name_unicode(self): |
1633 |
| - # issue #13292 |
1634 |
| - greek = u'\u0394\u03bf\u03ba\u03b9\u03bc\u03ae' |
1635 |
| - frame = pd.DataFrame({'foo': [1, 2, 3]}) |
1636 |
| - table = pd.pivot_table(frame, index=['foo'], aggfunc=len, margins=True, |
1637 |
| - margins_name=greek) |
1638 |
| - index = pd.Index([1, 2, 3, greek], dtype='object', name='foo') |
1639 |
| - expected = pd.DataFrame(index=index) |
1640 |
| - tm.assert_frame_equal(table, expected) |
0 commit comments