test_cumulative.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import pytest
  2. import pandas._testing as tm
  3. from pandas.core.arrays import DatetimeArray
  4. class TestAccumulator:
  5. def test_accumulators_freq(self):
  6. # GH#50297
  7. arr = DatetimeArray._from_sequence_not_strict(
  8. [
  9. "2000-01-01",
  10. "2000-01-02",
  11. "2000-01-03",
  12. ],
  13. freq="D",
  14. )
  15. result = arr._accumulate("cummin")
  16. expected = DatetimeArray._from_sequence_not_strict(
  17. ["2000-01-01"] * 3, freq=None
  18. )
  19. tm.assert_datetime_array_equal(result, expected)
  20. result = arr._accumulate("cummax")
  21. expected = DatetimeArray._from_sequence_not_strict(
  22. [
  23. "2000-01-01",
  24. "2000-01-02",
  25. "2000-01-03",
  26. ],
  27. freq=None,
  28. )
  29. tm.assert_datetime_array_equal(result, expected)
  30. @pytest.mark.parametrize("func", ["cumsum", "cumprod"])
  31. def test_accumulators_disallowed(self, func):
  32. # GH#50297
  33. arr = DatetimeArray._from_sequence_not_strict(
  34. [
  35. "2000-01-01",
  36. "2000-01-02",
  37. ],
  38. freq="D",
  39. )
  40. with pytest.raises(TypeError, match=f"Accumulation {func}"):
  41. arr._accumulate(func)