test_exceptions.py 1002 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import pytest
  2. jinja2 = pytest.importorskip("jinja2")
  3. from pandas import (
  4. DataFrame,
  5. MultiIndex,
  6. )
  7. from pandas.io.formats.style import Styler
  8. @pytest.fixture
  9. def df():
  10. return DataFrame(
  11. data=[[0, -0.609], [1, -1.228]],
  12. columns=["A", "B"],
  13. index=["x", "y"],
  14. )
  15. @pytest.fixture
  16. def styler(df):
  17. return Styler(df, uuid_len=0)
  18. def test_concat_bad_columns(styler):
  19. msg = "`other.data` must have same columns as `Styler.data"
  20. with pytest.raises(ValueError, match=msg):
  21. styler.concat(DataFrame([[1, 2]]).style)
  22. def test_concat_bad_type(styler):
  23. msg = "`other` must be of type `Styler`"
  24. with pytest.raises(TypeError, match=msg):
  25. styler.concat(DataFrame([[1, 2]]))
  26. def test_concat_bad_index_levels(styler, df):
  27. df = df.copy()
  28. df.index = MultiIndex.from_tuples([(0, 0), (1, 1)])
  29. msg = "number of index levels must be same in `other`"
  30. with pytest.raises(ValueError, match=msg):
  31. styler.concat(df.style)