From 48c163f9d7682b6b6f74693c3a2987839d89a271 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Mon, 23 May 2022 12:42:22 +0200 Subject: [PATCH] actually working in-memory conversion to hdf5 file --- utils/df_utils.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/utils/df_utils.py b/utils/df_utils.py index d256b04..7114cf0 100644 --- a/utils/df_utils.py +++ b/utils/df_utils.py @@ -25,10 +25,20 @@ def to_excel_binary(df, **kwargs): res = out.getvalue() return res -def to_hdf_binary(df, key="df", **kwargs): - with BytesIO() as out: - df.to_hdf(out, key, **kwargs) - res = out.getvalue() + + +from pandas import HDFStore + + +def to_hdf_binary(df): + with HDFStore( + "wontbewritten.h5", + mode="a", + driver="H5FD_CORE", + driver_core_backing_store=0 + ) as out: + out["/data"] = df + res = out._handle.get_file_image() return res