Skip to content

Commit 985bc74

Browse files
avalentinopmhatre1
authored andcommitted
Avoid unnecessary re-opening of HDF5 files (Closes: pandas-dev#58248) (pandas-dev#58275)
* Avoid unnecessary re-opening of HDF5 files * Update the whatsnew file * Move the changelog entry for pandas-dev#58248 to the correct section
1 parent c8c90fe commit 985bc74

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

pandas/io/pytables.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,14 @@ def to_hdf(
292292
dropna=dropna,
293293
)
294294

295-
path_or_buf = stringify_path(path_or_buf)
296-
if isinstance(path_or_buf, str):
295+
if isinstance(path_or_buf, HDFStore):
296+
f(path_or_buf)
297+
else:
298+
path_or_buf = stringify_path(path_or_buf)
297299
with HDFStore(
298300
path_or_buf, mode=mode, complevel=complevel, complib=complib
299301
) as store:
300302
f(store)
301-
else:
302-
f(path_or_buf)
303303

304304

305305
def read_hdf(

0 commit comments

Comments
 (0)