Skip to content

Commit aad77d6

Browse files
committed
update
1 parent baa77c3 commit aad77d6

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

doc/source/install.rst

+1
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ psycopg2 PostgreSQL engine for sqlalchemy
286286
pyarrow 0.9.0 Parquet and feather reading / writing
287287
pymysql MySQL engine for sqlalchemy
288288
pyreadstat SPSS files (.sav) reading
289+
pytables 3.4.2 HDF5 reading / writing
289290
qtpy Clipboard I/O
290291
s3fs 0.0.8 Amazon S3 access
291292
xarray 0.8.2 pandas-like API for N-dimensional data

pandas/compat/_optional.py

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"s3fs": "0.0.8",
2020
"scipy": "0.19.0",
2121
"sqlalchemy": "1.1.4",
22+
"tables": "3.4.2",
2223
"xarray": "0.8.2",
2324
"xlrd": "1.1.0",
2425
"xlwt": "1.2.0",

pandas/io/pytables.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from pandas._libs import lib, writers as libwriters
2121
from pandas._libs.tslibs import timezones
22+
from pandas.compat._optional import import_optional_dependency
2223
from pandas.errors import PerformanceWarning
2324

2425
from pandas.core.dtypes.common import (
@@ -448,11 +449,7 @@ def __init__(self, path, mode=None, complevel=None, complib=None,
448449
if 'format' in kwargs:
449450
raise ValueError('format is not a defined argument for HDFStore')
450451

451-
try:
452-
import tables # noqa
453-
except ImportError as ex: # pragma: no cover
454-
raise ImportError('HDFStore requires PyTables, "{ex!s}" problem '
455-
'importing'.format(ex=ex))
452+
tables = import_optional_dependency("tables")
456453

457454
if complib is not None and complib not in tables.filters.all_complibs:
458455
raise ValueError(

pandas/tests/test_optional_dependency.py

+10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import pytest
55

66
from pandas.compat._optional import VERSIONS, import_optional_dependency
7+
import pandas.util._test_decorators as td
78

9+
import pandas as pd
810
import pandas.util.testing as tm
911

1012

@@ -50,3 +52,11 @@ def test_no_version_raises():
5052

5153
with pytest.raises(ImportError, match="Can't determine .* fakemodule"):
5254
import_optional_dependency(name)
55+
56+
57+
@td.skip_if_installed("tables")
58+
def test_pytables_raises():
59+
df = pd.DataFrame({"A": [1, 2]})
60+
with pytest.raises(ImportError, match="tables"):
61+
with tm.ensure_clean("foo.h5") as path:
62+
df.to_hdf(path, "df")

pandas/util/_test_decorators.py

+17
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,23 @@ def _skip_if_no_scipy():
9999
safe_import('scipy.signal'))
100100

101101

102+
def skip_if_installed(
103+
package: str,
104+
) -> MarkDecorator:
105+
"""
106+
Skip a test if a package is installed.
107+
108+
Parameters
109+
----------
110+
package : str
111+
The name of the package.
112+
"""
113+
return pytest.mark.skipif(
114+
safe_import(package),
115+
reason="Skipping because {} is installed.".format(package)
116+
)
117+
118+
102119
def skip_if_no(
103120
package: str,
104121
min_version: Optional[str] = None

0 commit comments

Comments
 (0)