test_pickle.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import pytest
  2. from pandas import (
  3. NaT,
  4. date_range,
  5. to_datetime,
  6. )
  7. import pandas._testing as tm
  8. class TestPickle:
  9. def test_pickle(self):
  10. # GH#4606
  11. idx = to_datetime(["2013-01-01", NaT, "2014-01-06"])
  12. idx_p = tm.round_trip_pickle(idx)
  13. assert idx_p[0] == idx[0]
  14. assert idx_p[1] is NaT
  15. assert idx_p[2] == idx[2]
  16. def test_pickle_dont_infer_freq(self):
  17. # GH#11002
  18. # don't infer freq
  19. idx = date_range("1750-1-1", "2050-1-1", freq="7D")
  20. idx_p = tm.round_trip_pickle(idx)
  21. tm.assert_index_equal(idx, idx_p)
  22. def test_pickle_after_set_freq(self):
  23. dti = date_range("20130101", periods=3, tz="US/Eastern", name="foo")
  24. dti = dti._with_freq(None)
  25. res = tm.round_trip_pickle(dti)
  26. tm.assert_index_equal(res, dti)
  27. def test_roundtrip_pickle_with_tz(self):
  28. # GH#8367
  29. # round-trip of timezone
  30. index = date_range("20130101", periods=3, tz="US/Eastern", name="foo")
  31. unpickled = tm.round_trip_pickle(index)
  32. tm.assert_index_equal(index, unpickled)
  33. @pytest.mark.parametrize("freq", ["B", "C"])
  34. def test_pickle_unpickle(self, freq):
  35. rng = date_range("2009-01-01", "2010-01-01", freq=freq)
  36. unpickled = tm.round_trip_pickle(rng)
  37. assert unpickled.freq == freq