test_errors.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- coding: utf-8 -*-
  2. import pytest
  3. from pandas.errors import AbstractMethodError
  4. import pandas as pd # noqa
  5. @pytest.mark.parametrize(
  6. "exc", ['UnsupportedFunctionCall', 'UnsortedIndexError',
  7. 'OutOfBoundsDatetime',
  8. 'ParserError', 'PerformanceWarning', 'DtypeWarning',
  9. 'EmptyDataError', 'ParserWarning', 'MergeError'])
  10. def test_exception_importable(exc):
  11. from pandas import errors
  12. e = getattr(errors, exc)
  13. assert e is not None
  14. # check that we can raise on them
  15. with pytest.raises(e):
  16. raise e()
  17. def test_catch_oob():
  18. from pandas import errors
  19. try:
  20. pd.Timestamp('15000101')
  21. except errors.OutOfBoundsDatetime:
  22. pass
  23. def test_error_rename():
  24. # see gh-12665
  25. from pandas.errors import ParserError
  26. from pandas.io.common import CParserError
  27. try:
  28. raise CParserError()
  29. except ParserError:
  30. pass
  31. try:
  32. raise ParserError()
  33. except CParserError:
  34. pass
  35. class Foo(object):
  36. @classmethod
  37. def classmethod(cls):
  38. raise AbstractMethodError(cls, methodtype='classmethod')
  39. @property
  40. def property(self):
  41. raise AbstractMethodError(self, methodtype='property')
  42. def method(self):
  43. raise AbstractMethodError(self)
  44. def test_AbstractMethodError_classmethod():
  45. xpr = "This classmethod must be defined in the concrete class Foo"
  46. with pytest.raises(AbstractMethodError, match=xpr):
  47. Foo.classmethod()
  48. xpr = "This property must be defined in the concrete class Foo"
  49. with pytest.raises(AbstractMethodError, match=xpr):
  50. Foo().property
  51. xpr = "This method must be defined in the concrete class Foo"
  52. with pytest.raises(AbstractMethodError, match=xpr):
  53. Foo().method()