test_join.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import numpy as np
  2. from pandas import Index, Timedelta, timedelta_range
  3. import pandas._testing as tm
  4. class TestJoin:
  5. def test_append_join_nondatetimeindex(self):
  6. rng = timedelta_range("1 days", periods=10)
  7. idx = Index(["a", "b", "c", "d"])
  8. result = rng.append(idx)
  9. assert isinstance(result[0], Timedelta)
  10. # it works
  11. rng.join(idx, how="outer")
  12. def test_join_self(self, join_type):
  13. index = timedelta_range("1 day", periods=10)
  14. joined = index.join(index, how=join_type)
  15. tm.assert_index_equal(index, joined)
  16. def test_does_not_convert_mixed_integer(self):
  17. df = tm.makeCustomDataframe(
  18. 10,
  19. 10,
  20. data_gen_f=lambda *args, **kwargs: np.random.randn(),
  21. r_idx_type="i",
  22. c_idx_type="td",
  23. )
  24. str(df)
  25. cols = df.columns.join(df.index, how="outer")
  26. joined = cols.join(df.columns)
  27. assert cols.dtype == np.dtype("O")
  28. assert cols.dtype == joined.dtype
  29. tm.assert_index_equal(cols, joined)
  30. def test_join_preserves_freq(self):
  31. # GH#32157
  32. tdi = timedelta_range("1 day", periods=10)
  33. result = tdi[:5].join(tdi[5:], how="outer")
  34. assert result.freq == tdi.freq
  35. tm.assert_index_equal(result, tdi)
  36. result = tdi[:5].join(tdi[6:], how="outer")
  37. assert result.freq is None
  38. expected = tdi.delete(5)
  39. tm.assert_index_equal(result, expected)