test_periodindex.py 556 B

1234567891011121314151617181920212223242526
  1. import pytest
  2. from pandas import (
  3. Period,
  4. PeriodIndex,
  5. Series,
  6. period_range,
  7. )
  8. import pandas._testing as tm
  9. @pytest.mark.parametrize(
  10. "cons",
  11. [
  12. lambda x: PeriodIndex(x),
  13. lambda x: PeriodIndex(PeriodIndex(x)),
  14. ],
  15. )
  16. def test_periodindex(using_copy_on_write, cons):
  17. dt = period_range("2019-12-31", periods=3, freq="D")
  18. ser = Series(dt)
  19. idx = cons(ser)
  20. expected = idx.copy(deep=True)
  21. ser.iloc[0] = Period("2020-12-31")
  22. if using_copy_on_write:
  23. tm.assert_index_equal(idx, expected)