test_missing.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import pytest
  2. import pandas as pd
  3. import pandas.util.testing as tm
  4. class TestDatetimeIndex(object):
  5. @pytest.mark.parametrize('tz', ['US/Eastern', 'Asia/Tokyo'])
  6. def test_fillna_datetime64(self, tz):
  7. # GH 11343
  8. idx = pd.DatetimeIndex(['2011-01-01 09:00', pd.NaT,
  9. '2011-01-01 11:00'])
  10. exp = pd.DatetimeIndex(['2011-01-01 09:00', '2011-01-01 10:00',
  11. '2011-01-01 11:00'])
  12. tm.assert_index_equal(
  13. idx.fillna(pd.Timestamp('2011-01-01 10:00')), exp)
  14. # tz mismatch
  15. exp = pd.Index([pd.Timestamp('2011-01-01 09:00'),
  16. pd.Timestamp('2011-01-01 10:00', tz=tz),
  17. pd.Timestamp('2011-01-01 11:00')], dtype=object)
  18. tm.assert_index_equal(
  19. idx.fillna(pd.Timestamp('2011-01-01 10:00', tz=tz)), exp)
  20. # object
  21. exp = pd.Index([pd.Timestamp('2011-01-01 09:00'), 'x',
  22. pd.Timestamp('2011-01-01 11:00')], dtype=object)
  23. tm.assert_index_equal(idx.fillna('x'), exp)
  24. idx = pd.DatetimeIndex(['2011-01-01 09:00', pd.NaT,
  25. '2011-01-01 11:00'], tz=tz)
  26. exp = pd.DatetimeIndex(['2011-01-01 09:00', '2011-01-01 10:00',
  27. '2011-01-01 11:00'], tz=tz)
  28. tm.assert_index_equal(
  29. idx.fillna(pd.Timestamp('2011-01-01 10:00', tz=tz)), exp)
  30. exp = pd.Index([pd.Timestamp('2011-01-01 09:00', tz=tz),
  31. pd.Timestamp('2011-01-01 10:00'),
  32. pd.Timestamp('2011-01-01 11:00', tz=tz)],
  33. dtype=object)
  34. tm.assert_index_equal(
  35. idx.fillna(pd.Timestamp('2011-01-01 10:00')), exp)
  36. # object
  37. exp = pd.Index([pd.Timestamp('2011-01-01 09:00', tz=tz),
  38. 'x',
  39. pd.Timestamp('2011-01-01 11:00', tz=tz)],
  40. dtype=object)
  41. tm.assert_index_equal(idx.fillna('x'), exp)