test_index.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. """
  2. Tests for offset behavior with indices.
  3. """
  4. import pytest
  5. from pandas import (
  6. Series,
  7. date_range,
  8. )
  9. from pandas.tseries.offsets import (
  10. BMonthBegin,
  11. BMonthEnd,
  12. BQuarterBegin,
  13. BQuarterEnd,
  14. BYearBegin,
  15. BYearEnd,
  16. MonthBegin,
  17. MonthEnd,
  18. QuarterBegin,
  19. QuarterEnd,
  20. YearBegin,
  21. YearEnd,
  22. )
  23. @pytest.mark.parametrize("n", [-2, 1])
  24. @pytest.mark.parametrize(
  25. "cls",
  26. [
  27. MonthBegin,
  28. MonthEnd,
  29. BMonthBegin,
  30. BMonthEnd,
  31. QuarterBegin,
  32. QuarterEnd,
  33. BQuarterBegin,
  34. BQuarterEnd,
  35. YearBegin,
  36. YearEnd,
  37. BYearBegin,
  38. BYearEnd,
  39. ],
  40. )
  41. def test_apply_index(cls, n):
  42. offset = cls(n=n)
  43. rng = date_range(start="1/1/2000", periods=100000, freq="T")
  44. ser = Series(rng)
  45. res = rng + offset
  46. assert res.freq is None # not retained
  47. assert res[0] == rng[0] + offset
  48. assert res[-1] == rng[-1] + offset
  49. res2 = ser + offset
  50. # apply_index is only for indexes, not series, so no res2_v2
  51. assert res2.iloc[0] == ser.iloc[0] + offset
  52. assert res2.iloc[-1] == ser.iloc[-1] + offset