From 0ee6707d9b23c91aa2a28aa4c8393da5fddbc7e8 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Fri, 27 May 2022 20:46:59 +0200 Subject: [PATCH] restructure --- download.py | 2 +- tableapi.py | 2 +- utils/df2bin.py | 27 +++++++++++++++++++++++++++ utils/{df_utils.py => dfh.py} | 27 --------------------------- 4 files changed, 29 insertions(+), 29 deletions(-) create mode 100644 utils/df2bin.py rename utils/{df_utils.py => dfh.py} (68%) diff --git a/download.py b/download.py index d3cee77..a28f86d 100644 --- a/download.py +++ b/download.py @@ -1,6 +1,6 @@ import streamlit as st -from utils.df_utils import to_excel_binary, to_hdf_binary +from utils.df2bin import to_excel_binary, to_hdf_binary state = st.session_state diff --git a/tableapi.py b/tableapi.py index 7607523..589d238 100644 --- a/tableapi.py +++ b/tableapi.py @@ -1,6 +1,6 @@ import cherrypy as cp -from utils.df_utils import DateFrameHolder +from utils.dfh import DateFrameHolder from utils.st_utils import rerun diff --git a/utils/df2bin.py b/utils/df2bin.py new file mode 100644 index 0000000..9158459 --- /dev/null +++ b/utils/df2bin.py @@ -0,0 +1,27 @@ +from io import BytesIO + + +def to_excel_binary(df, **kwargs): + with BytesIO() as out: + df.to_excel(out, **kwargs) + res = out.getvalue() + return res + + + +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 + + + diff --git a/utils/df_utils.py b/utils/dfh.py similarity index 68% rename from utils/df_utils.py rename to utils/dfh.py index 6b8ad89..25dd1be 100644 --- a/utils/df_utils.py +++ b/utils/dfh.py @@ -45,30 +45,3 @@ def dump_non_empty_df(df, fn, key="data"): -from io import BytesIO - - -def to_excel_binary(df, **kwargs): - with BytesIO() as out: - df.to_excel(out, **kwargs) - res = out.getvalue() - return res - - - -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 - - -