Skip to content

Enh move pytable errors and warnings #47662

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
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
4 changes: 4 additions & 0 deletions doc/source/reference/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ Exceptions and warnings

errors.AbstractMethodError
errors.AccessorRegistrationWarning
errors.AttributeConflictWarning
errors.ClosedFileError
errors.CSSWarning
errors.DataError
errors.DtypeWarning
errors.DuplicateLabelError
errors.EmptyDataError
errors.IncompatibilityWarning
errors.IndexingError
errors.InvalidIndexError
errors.IntCastingNaNError
Expand All @@ -44,6 +47,7 @@ Exceptions and warnings
errors.ParserError
errors.ParserWarning
errors.PerformanceWarning
errors.PossibleDataLossError
errors.PyperclipException
errors.PyperclipWindowsException
errors.SettingWithCopyError
Expand Down
45 changes: 45 additions & 0 deletions pandas/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,58 @@ class CSSWarning(UserWarning):
"""


class PossibleDataLossError(Exception):
"""
Exception is raised when trying to open a HDFStore file when the file is already
opened.

Examples
--------
>>> store = pd.HDFStore('my-store', 'a') # doctest: +SKIP
>>> store.open("w") # doctest: +SKIP
... # PossibleDataLossError: Re-opening the file [my-store] with mode [a]...
"""


class ClosedFileError(Exception):
"""
Exception is raised when trying to perform an operation on a closed HDFStore file.

Examples
--------
>>> store = pd.HDFStore('my-store', 'a') # doctest: +SKIP
>>> store.close() # doctest: +SKIP
>>> store.keys() # doctest: +SKIP
... # ClosedFileError: my-store file is not open!
"""


class IncompatibilityWarning(Warning):
"""
Warning is raised when trying to use where criteria on an incompatible
HDF5 file.
"""


class AttributeConflictWarning(Warning):
"""
Warning is raised when attempting to append an index with a different
name than the existing index on an HDFStore or attempting to append an index with a
different frequency than the existing index on an HDFStore.
"""


__all__ = [
"AbstractMethodError",
"AccessorRegistrationWarning",
"AttributeConflictWarning",
"ClosedFileError",
"CSSWarning",
"DataError",
"DtypeWarning",
"DuplicateLabelError",
"EmptyDataError",
"IncompatibilityWarning",
"IntCastingNaNError",
"InvalidIndexError",
"IndexingError",
Expand All @@ -436,6 +480,7 @@ class CSSWarning(UserWarning):
"ParserError",
"ParserWarning",
"PerformanceWarning",
"PossibleDataLossError",
"PyperclipException",
"PyperclipWindowsException",
"SettingWithCopyError",
Expand Down
36 changes: 8 additions & 28 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@
)
from pandas.compat._optional import import_optional_dependency
from pandas.compat.pickle_compat import patch_pickle
from pandas.errors import PerformanceWarning
from pandas.errors import (
AttributeConflictWarning,
ClosedFileError,
IncompatibilityWarning,
PerformanceWarning,
PossibleDataLossError,
)
from pandas.util._decorators import cache_readonly
from pandas.util._exceptions import find_stack_level

Expand Down Expand Up @@ -169,43 +175,17 @@ def _ensure_term(where, scope_level: int):
return where if where is None or len(where) else None


class PossibleDataLossError(Exception):
pass


class ClosedFileError(Exception):
pass


class IncompatibilityWarning(Warning):
pass


incompatibility_doc = """
where criteria is being ignored as this version [%s] is too old (or
not-defined), read the file in and write it out to a new file to upgrade (with
the copy_to method)
"""


class AttributeConflictWarning(Warning):
pass


attribute_conflict_doc = """
the [%s] attribute of the existing index is [%s] which conflicts with the new
[%s], resetting the attribute to None
"""


class DuplicateWarning(Warning):
pass


duplicate_doc = """
duplicate entries in table, taking most recently appended
"""

performance_doc = """
your performance may suffer as PyTables will pickle object types that it cannot
map directly to c-types [inferred_type->%s,key->%s] [items->%s]
Expand Down Expand Up @@ -3550,7 +3530,7 @@ def get_attrs(self) -> None:
def validate_version(self, where=None) -> None:
"""are we trying to operate on an old version?"""
if where is not None:
if self.version[0] <= 0 and self.version[1] <= 10 and self.version[2] < 1:
if self.is_old_version:
ws = incompatibility_doc % ".".join([str(x) for x in self.version])
warnings.warn(ws, IncompatibilityWarning)

Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/io/pytables/test_file_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import pytest

from pandas.compat import is_platform_little_endian
from pandas.errors import (
ClosedFileError,
PossibleDataLossError,
)

from pandas import (
DataFrame,
Expand All @@ -20,11 +24,7 @@
)

from pandas.io import pytables as pytables
from pandas.io.pytables import (
ClosedFileError,
PossibleDataLossError,
Term,
)
from pandas.io.pytables import Term

pytestmark = pytest.mark.single_cpu

Expand Down
1 change: 0 additions & 1 deletion pandas/tests/io/pytables/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,6 @@ def test_store_series_name(setup_path):
tm.assert_series_equal(recons, series)


@pytest.mark.filterwarnings("ignore:\\nduplicate:pandas.io.pytables.DuplicateWarning")
def test_overwrite_node(setup_path):

with ensure_clean_store(setup_path) as store:
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
"IndexingError",
"PyperclipException",
"CSSWarning",
"ClosedFileError",
"PossibleDataLossError",
"IncompatibilityWarning",
"AttributeConflictWarning",
],
)
def test_exception_importable(exc):
Expand Down