Skip to content

Commit 73d4f85

Browse files
committed
BUG: Fix read_hdf closing store that it didn't open (GH28699)
1 parent 9ab3478 commit 73d4f85

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

pandas/io/pytables.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,12 @@ def read_hdf(path_or_buf, key=None, mode="r", **kwargs):
396396
key = candidate_only_group._v_pathname
397397
return store.select(key, auto_close=auto_close, **kwargs)
398398
except (ValueError, TypeError, KeyError):
399-
# if there is an error, close the store
400-
try:
401-
store.close()
402-
except AttributeError:
403-
pass
399+
if not isinstance(path_or_buf, HDFStore):
400+
# if there is an error, close the store if we opened it.
401+
try:
402+
store.close()
403+
except AttributeError:
404+
pass
404405

405406
raise
406407

0 commit comments

Comments
 (0)