Skip to content

ENH: Move database error to error/__init__.py per GH27656 #47674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/reference/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Exceptions and warnings
errors.AttributeConflictWarning
errors.ClosedFileError
errors.CSSWarning
errors.DatabaseError
errors.DataError
errors.DtypeWarning
errors.DuplicateLabelError
Expand Down
14 changes: 14 additions & 0 deletions pandas/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,26 @@ class AttributeConflictWarning(Warning):
"""


class DatabaseError(OSError):
"""
Error is raised when executing sql with bad syntax or sql that throws an error.
Examples
--------
>>> from sqlite3 import connect
>>> conn = connect(':memory:')
>>> pd.read_sql('select * test', conn) # doctest: +SKIP
... # DatabaseError: Execution failed on sql 'test': near "test": syntax error
"""


__all__ = [
"AbstractMethodError",
"AccessorRegistrationWarning",
"AttributeConflictWarning",
"ClosedFileError",
"CSSWarning",
"DatabaseError",
"DataError",
"DtypeWarning",
"DuplicateLabelError",
Expand Down
9 changes: 4 additions & 5 deletions pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
DtypeArg,
)
from pandas.compat._optional import import_optional_dependency
from pandas.errors import AbstractMethodError
from pandas.errors import (
AbstractMethodError,
DatabaseError,
)
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.common import (
Expand All @@ -56,10 +59,6 @@
from sqlalchemy import Table


class DatabaseError(OSError):
pass


# -----------------------------------------------------------------------------
# -- Helper functions

Expand Down
1 change: 1 addition & 0 deletions pandas/tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"PossibleDataLossError",
"IncompatibilityWarning",
"AttributeConflictWarning",
"DatabaseError",
],
)
def test_exception_importable(exc):
Expand Down