PageRenderTime 63ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/pandas/tseries/tests/test_util.py

https://github.com/kljensen/pandas
Python | 79 lines | 50 code | 25 blank | 4 comment | 5 complexity | 3b7c8d7b4e97da6c009b20e32ecb3325 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 datetime import datetime, date
  7. from pandas.tseries.tools import normalize_date
  8. from pandas.tseries.util import pivot_annual, isleapyear
  9. class TestPivotAnnual(unittest.TestCase):
  10. """
  11. New pandas of scikits.timeseries pivot_annual
  12. """
  13. def test_daily(self):
  14. rng = date_range('1/1/2000', '12/31/2004', freq='D')
  15. ts = Series(np.random.randn(len(rng)), index=rng)
  16. annual = pivot_annual(ts, 'D')
  17. doy = ts.index.dayofyear
  18. doy[(-isleapyear(ts.index.year)) & (doy >= 60)] += 1
  19. for i in range(1, 367):
  20. subset = ts[doy == i]
  21. subset.index = [x.year for x in subset.index]
  22. tm.assert_series_equal(annual[i].dropna(), subset)
  23. # check leap days
  24. leaps = ts[(ts.index.month == 2) & (ts.index.day == 29)]
  25. day = leaps.index.dayofyear[0]
  26. leaps.index = leaps.index.year
  27. tm.assert_series_equal(annual[day].dropna(), leaps)
  28. def test_weekly(self):
  29. pass
  30. def test_monthly(self):
  31. rng = date_range('1/1/2000', '12/31/2004', freq='M')
  32. ts = Series(np.random.randn(len(rng)), index=rng)
  33. annual = pivot_annual(ts, 'M')
  34. month = ts.index.month
  35. for i in range(1, 13):
  36. subset = ts[month == i]
  37. subset.index = [x.year for x in subset.index]
  38. tm.assert_series_equal(annual[i].dropna(), subset)
  39. def test_period_monthly(self):
  40. pass
  41. def test_period_daily(self):
  42. pass
  43. def test_period_weekly(self):
  44. pass
  45. def test_normalize_date():
  46. value = date(2012, 9, 7)
  47. result = normalize_date(value)
  48. assert(result == datetime(2012, 9, 7))
  49. value = datetime(2012, 9, 7, 12)
  50. result = normalize_date(value)
  51. assert(result == datetime(2012, 9, 7))
  52. if __name__ == '__main__':
  53. nose.runmodule(argv=[__file__,'-vvs','-x','--pdb', '--pdb-failure'],
  54. exit=False)