PageRenderTime 52ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/pandas/tseries/tests/test_util.py

https://github.com/lenolib/pandas
Python | 64 lines | 41 code | 19 blank | 4 comment | 5 complexity | 0b1fc9d27596adf470d06a74de67bc95 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. import nose
  2. import unittest
  3. import numpy as np
  4. from pandas import Series, date_range
  5. import pandas.util.testing as tm
  6. from pandas.tseries.util import pivot_annual, isleapyear
  7. class TestPivotAnnual(unittest.TestCase):
  8. """
  9. New pandas of scikits.timeseries pivot_annual
  10. """
  11. def test_daily(self):
  12. rng = date_range('1/1/2000', '12/31/2004', freq='D')
  13. ts = Series(np.random.randn(len(rng)), index=rng)
  14. annual = pivot_annual(ts, 'D')
  15. doy = ts.index.dayofyear
  16. doy[(-isleapyear(ts.index.year)) & (doy >= 60)] += 1
  17. for i in range(1, 367):
  18. subset = ts[doy == i]
  19. subset.index = [x.year for x in subset.index]
  20. tm.assert_series_equal(annual[i].dropna(), subset)
  21. # check leap days
  22. leaps = ts[(ts.index.month == 2) & (ts.index.day == 29)]
  23. day = leaps.index.dayofyear[0]
  24. leaps.index = leaps.index.year
  25. tm.assert_series_equal(annual[day].dropna(), leaps)
  26. def test_weekly(self):
  27. pass
  28. def test_monthly(self):
  29. rng = date_range('1/1/2000', '12/31/2004', freq='M')
  30. ts = Series(np.random.randn(len(rng)), index=rng)
  31. annual = pivot_annual(ts, 'M')
  32. month = ts.index.month
  33. for i in range(1, 13):
  34. subset = ts[month == i]
  35. subset.index = [x.year for x in subset.index]
  36. tm.assert_series_equal(annual[i].dropna(), subset)
  37. def test_period_monthly(self):
  38. pass
  39. def test_period_daily(self):
  40. pass
  41. def test_period_weekly(self):
  42. pass
  43. if __name__ == '__main__':
  44. nose.runmodule(argv=[__file__,'-vvs','-x','--pdb', '--pdb-failure'],
  45. exit=False)