Skip to content

Commit a504f4f

Browse files
committed
test that IndexError closes hdf files
1 parent f336549 commit a504f4f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pandas/tests/io/pytables/test_read.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ def test_read_missing_key_close_store(tmp_path, setup_path):
4242
df.to_hdf(path, "k2")
4343

4444

45+
def test_read_index_error_close_store(tmp_path, setup_path):
46+
# GH 25766
47+
path = tmp_path / setup_path
48+
df = pd.DataFrame({"A": [], "B": []}, index=[])
49+
df.to_hdf(path, "k1")
50+
51+
with pytest.raises(IndexError, match=r"list index out of range"):
52+
read_hdf(path, "k1", stop=0)
53+
54+
# smoke test to test that file is properly closed after
55+
# read with IndexError before another write
56+
df.to_hdf(path, "k1")
57+
58+
4559
def test_read_missing_key_opened_store(tmp_path, setup_path):
4660
# GH 28699
4761
path = tmp_path / setup_path

0 commit comments

Comments
 (0)