Skip to content

Commit

Permalink
Avoid unnecessary re-opening of HDF5 files (Closes: pandas-dev#58248) (
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
avalentino committed Apr 16, 2024
1 parent 8131381 commit bb0fcc2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ Performance improvements
- Performance improvement in :meth:`RangeIndex.reindex` returning a :class:`RangeIndex` instead of a :class:`Index` when possible. (:issue:`57647`, :issue:`57752`)
- Performance improvement in :meth:`RangeIndex.take` returning a :class:`RangeIndex` instead of a :class:`Index` when possible. (:issue:`57445`, :issue:`57752`)
- Performance improvement in :func:`merge` if hash-join can be used (:issue:`57970`)
- 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`)
- Performance improvement in ``DataFrameGroupBy.__len__`` and ``SeriesGroupBy.__len__`` (:issue:`57595`)
- Performance improvement in indexing operations for string dtypes (:issue:`56997`)
- Performance improvement in unary methods on a :class:`RangeIndex` returning a :class:`RangeIndex` instead of a :class:`Index` when possible. (:issue:`57825`)
Expand Down Expand Up @@ -406,7 +407,6 @@ I/O
- Bug in :meth:`DataFrame.to_string` that raised ``StopIteration`` with nested DataFrames. (:issue:`16098`)
- Bug in :meth:`read_csv` raising ``TypeError`` when ``index_col`` is specified and ``na_values`` is a dict containing the key ``None``. (:issue:`57547`)


Period
^^^^^^
-
Expand Down
8 changes: 4 additions & 4 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,14 @@ def to_hdf(
dropna=dropna,
)

path_or_buf = stringify_path(path_or_buf)
if isinstance(path_or_buf, str):
if isinstance(path_or_buf, HDFStore):
f(path_or_buf)
else:
path_or_buf = stringify_path(path_or_buf)
with HDFStore(
path_or_buf, mode=mode, complevel=complevel, complib=complib
) as store:
f(store)
else:
f(path_or_buf)


def read_hdf(
Expand Down

0 comments on commit bb0fcc2

Please sign in to comment.