Skip to content

Commit 6481243

Browse files
committed
TST: Add test for read_hdf store closing bug (GH28699)
1 parent 8fd2c39 commit 6481243

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

pandas/tests/io/pytables/test_pytables.py

+15
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,21 @@ def test_read_missing_key_close_store(self):
13011301
# read with KeyError before another write
13021302
df.to_hdf(path, "k2")
13031303

1304+
def test_read_missing_key_opened_store(self):
1305+
# GH 28699
1306+
with ensure_clean_path(self.path) as path:
1307+
df = pd.DataFrame({"a": range(2), "b": range(2)})
1308+
df.to_hdf(path, "k1")
1309+
1310+
store = pd.HDFStore(path, 'r')
1311+
1312+
with pytest.raises(KeyError, match="'No object named k2 in the file'"):
1313+
pd.read_hdf(store, "k2")
1314+
1315+
# Test that the file is still open after a KeyError and that we can
1316+
# still read from it.
1317+
pd.read_hdf(store, "k1")
1318+
13041319
def test_append_frame_column_oriented(self):
13051320

13061321
with ensure_clean_store(self.path) as store:

0 commit comments

Comments
 (0)