test_fillna.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from pandas import (
  2. Index,
  3. NaT,
  4. Period,
  5. PeriodIndex,
  6. )
  7. import pandas._testing as tm
  8. class TestFillNA:
  9. def test_fillna_period(self):
  10. # GH#11343
  11. idx = PeriodIndex(["2011-01-01 09:00", NaT, "2011-01-01 11:00"], freq="H")
  12. exp = PeriodIndex(
  13. ["2011-01-01 09:00", "2011-01-01 10:00", "2011-01-01 11:00"], freq="H"
  14. )
  15. result = idx.fillna(Period("2011-01-01 10:00", freq="H"))
  16. tm.assert_index_equal(result, exp)
  17. exp = Index(
  18. [
  19. Period("2011-01-01 09:00", freq="H"),
  20. "x",
  21. Period("2011-01-01 11:00", freq="H"),
  22. ],
  23. dtype=object,
  24. )
  25. result = idx.fillna("x")
  26. tm.assert_index_equal(result, exp)
  27. exp = Index(
  28. [
  29. Period("2011-01-01 09:00", freq="H"),
  30. Period("2011-01-01", freq="D"),
  31. Period("2011-01-01 11:00", freq="H"),
  32. ],
  33. dtype=object,
  34. )
  35. result = idx.fillna(Period("2011-01-01", freq="D"))
  36. tm.assert_index_equal(result, exp)