Skip to content

Commit 639e365

Browse files
committed
TST: Add test for read_hdf store closing bug (GH28699)
1 parent 73d4f85 commit 639e365

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pandas/tests/io/pytables/test_pytables.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,22 @@ def test_read_missing_key_close_store(self, setup_path):
12941294
# read with KeyError before another write
12951295
df.to_hdf(path, "k2")
12961296

1297-
def test_append_frame_column_oriented(self, setup_path):
1297+
def test_read_missing_key_opened_store(self, setup_path):
1298+
# GH 28699
1299+
with ensure_clean_path(setup_path) as path:
1300+
df = pd.DataFrame({"a": range(2), "b": range(2)})
1301+
df.to_hdf(path, "k1")
1302+
1303+
store = pd.HDFStore(path, 'r')
12981304

1305+
with pytest.raises(KeyError, match="'No object named k2 in the file'"):
1306+
pd.read_hdf(store, "k2")
1307+
1308+
# Test that the file is still open after a KeyError and that we can
1309+
# still read from it.
1310+
pd.read_hdf(store, "k1")
1311+
1312+
def test_append_frame_column_oriented(self, setup_path):
12991313
with ensure_clean_store(setup_path) as store:
13001314

13011315
# column oriented

0 commit comments

Comments
 (0)