Skip to content

Commit 5690e8f

Browse files
authored
ENH: Move database error to error/__init__.py per GH27656 (#47674)
* ENH: Move error to error/__init__.py per GH27656 * ENH: apply feedback * ENH: remove import
1 parent 13e859f commit 5690e8f

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

doc/source/reference/testing.rst

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Exceptions and warnings
2929
errors.AttributeConflictWarning
3030
errors.ClosedFileError
3131
errors.CSSWarning
32+
errors.DatabaseError
3233
errors.DataError
3334
errors.DtypeWarning
3435
errors.DuplicateLabelError

pandas/errors/__init__.py

+14
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,26 @@ class AttributeConflictWarning(Warning):
456456
"""
457457

458458

459+
class DatabaseError(OSError):
460+
"""
461+
Error is raised when executing sql with bad syntax or sql that throws an error.
462+
463+
Examples
464+
--------
465+
>>> from sqlite3 import connect
466+
>>> conn = connect(':memory:')
467+
>>> pd.read_sql('select * test', conn) # doctest: +SKIP
468+
... # DatabaseError: Execution failed on sql 'test': near "test": syntax error
469+
"""
470+
471+
459472
__all__ = [
460473
"AbstractMethodError",
461474
"AccessorRegistrationWarning",
462475
"AttributeConflictWarning",
463476
"ClosedFileError",
464477
"CSSWarning",
478+
"DatabaseError",
465479
"DataError",
466480
"DtypeWarning",
467481
"DuplicateLabelError",

pandas/io/sql.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
DtypeArg,
3232
)
3333
from pandas.compat._optional import import_optional_dependency
34-
from pandas.errors import AbstractMethodError
34+
from pandas.errors import (
35+
AbstractMethodError,
36+
DatabaseError,
37+
)
3538
from pandas.util._exceptions import find_stack_level
3639

3740
from pandas.core.dtypes.common import (
@@ -56,10 +59,6 @@
5659
from sqlalchemy import Table
5760

5861

59-
class DatabaseError(OSError):
60-
pass
61-
62-
6362
# -----------------------------------------------------------------------------
6463
# -- Helper functions
6564

pandas/tests/test_errors.py

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"PossibleDataLossError",
3535
"IncompatibilityWarning",
3636
"AttributeConflictWarning",
37+
"DatabaseError",
3738
],
3839
)
3940
def test_exception_importable(exc):

0 commit comments

Comments
 (0)