test_join.py 1.5 KB

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