test_validate.py 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. import pytest
  2. from pandas.core.frame import DataFrame
  3. @pytest.fixture
  4. def dataframe():
  5. return DataFrame({'a': [1, 2], 'b': [3, 4]})
  6. class TestDataFrameValidate(object):
  7. """Tests for error handling related to data types of method arguments."""
  8. @pytest.mark.parametrize("func", ["query", "eval", "set_index",
  9. "reset_index", "dropna",
  10. "drop_duplicates", "sort_values"])
  11. @pytest.mark.parametrize("inplace", [1, "True", [1, 2, 3], 5.0])
  12. def test_validate_bool_args(self, dataframe, func, inplace):
  13. msg = "For argument \"inplace\" expected type bool"
  14. kwargs = dict(inplace=inplace)
  15. if func == "query":
  16. kwargs["expr"] = "a > b"
  17. elif func == "eval":
  18. kwargs["expr"] = "a + b"
  19. elif func == "set_index":
  20. kwargs["keys"] = ["a"]
  21. elif func == "sort_values":
  22. kwargs["by"] = ["a"]
  23. with pytest.raises(ValueError, match=msg):
  24. getattr(dataframe, func)(**kwargs)