Skip to content

Commit bb0fcc2

Browse files
authored
Avoid unnecessary re-opening of HDF5 files (Closes: #58248) (#58275)
* Avoid unnecessary re-opening of HDF5 files * Update the whatsnew file * Move the changelog entry for #58248 to the correct section
1 parent 8131381 commit bb0fcc2

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

doc/source/whatsnew/v3.0.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ Performance improvements
331331
- Performance improvement in :meth:`RangeIndex.reindex` returning a :class:`RangeIndex` instead of a :class:`Index` when possible. (:issue:`57647`, :issue:`57752`)
332332
- Performance improvement in :meth:`RangeIndex.take` returning a :class:`RangeIndex` instead of a :class:`Index` when possible. (:issue:`57445`, :issue:`57752`)
333333
- Performance improvement in :func:`merge` if hash-join can be used (:issue:`57970`)
334+
- Performance improvement in :meth:`to_hdf` avoid unnecessary reopenings of the HDF5 file to speedup data addition to files with a very large number of groups . (:issue:`58248`)
334335
- Performance improvement in ``DataFrameGroupBy.__len__`` and ``SeriesGroupBy.__len__`` (:issue:`57595`)
335336
- Performance improvement in indexing operations for string dtypes (:issue:`56997`)
336337
- Performance improvement in unary methods on a :class:`RangeIndex` returning a :class:`RangeIndex` instead of a :class:`Index` when possible. (:issue:`57825`)
@@ -406,7 +407,6 @@ I/O
406407
- Bug in :meth:`DataFrame.to_string` that raised ``StopIteration`` with nested DataFrames. (:issue:`16098`)
407408
- Bug in :meth:`read_csv` raising ``TypeError`` when ``index_col`` is specified and ``na_values`` is a dict containing the key ``None``. (:issue:`57547`)
408409

409-
410410
Period
411411
^^^^^^
412412
-

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)