From bfccf6d22afe2fa78322b86d00c0f16c63fa0d9d Mon Sep 17 00:00:00 2001
From: dave <dave@dtu.dk>
Date: Wed, 25 May 2016 13:44:46 +0200
Subject: [PATCH] prepost: df.to_hdf complib argument for misc.dict2df

---
 wetb/prepost/Simulations.py | 12 ++++++++----
 wetb/prepost/misc.py        |  9 +++++----
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/wetb/prepost/Simulations.py b/wetb/prepost/Simulations.py
index 5f2412c..5953852 100755
--- a/wetb/prepost/Simulations.py
+++ b/wetb/prepost/Simulations.py
@@ -4517,7 +4517,8 @@ class Cases(object):
                 # TODO: test this first
                 fname = os.path.join(post_dir, sim_id + '_statistics' + ext)
                 dfs = misc.dict2df(df_dict2, fname, save=save, update=update,
-                                   csv=csv, xlsx=xlsx, check_datatypes=False)
+                                   csv=csv, xlsx=xlsx, check_datatypes=False,
+                                   complib=self.complib)
 
                 df_dict2 = None
                 df_dict = None
@@ -4539,7 +4540,8 @@ class Cases(object):
             # TODO: test this first
             fname = os.path.join(post_dir, sim_id + '_statistics' + ext)
             dfs = misc.dict2df(df_dict2, fname, save=save, update=update,
-                               csv=csv, xlsx=xlsx, check_datatypes=False)
+                               csv=csv, xlsx=xlsx, check_datatypes=False,
+                               complib=self.complib)
 
         return dfs
 
@@ -4806,7 +4808,8 @@ class Cases(object):
         # make consistent data types, and convert to DataFrame
         fname = os.path.join(post_dir, sim_id + '_Leq')
         df_Leq = misc.dict2df(dict_Leq, fname, save=save, update=update,
-                              csv=csv, check_datatypes=True, xlsx=xlsx)
+                              csv=csv, check_datatypes=True, xlsx=xlsx,
+                              complib=self.complib)
 
         # only keep the ones that do not have nan's (only works with index)
         return df_Leq
@@ -4928,7 +4931,8 @@ class Cases(object):
         # make consistent data types, and convert to DataFrame
         fname = os.path.join(post_dir, sim_id + '_AEP')
         df_AEP = misc.dict2df(dict_AEP, fname, update=update, csv=csv,
-                              save=save, check_datatypes=True, xlsx=xlsx)
+                              save=save, check_datatypes=True, xlsx=xlsx,
+                              complib=self.complib)
 
         return df_AEP
 
diff --git a/wetb/prepost/misc.py b/wetb/prepost/misc.py
index f5cd5cf..b0bd749 100644
--- a/wetb/prepost/misc.py
+++ b/wetb/prepost/misc.py
@@ -1024,7 +1024,8 @@ def df_dict_check_datatypes(df_dict):
 
 
 def dict2df(df_dict, fname, save=True, update=False, csv=False, colsort=None,
-            check_datatypes=False, rowsort=None, csv_index=False, xlsx=False):
+            check_datatypes=False, rowsort=None, csv_index=False, xlsx=False,
+            complib='blosc'):
         """
         Convert the df_dict to df and save/update if required. If converting
         to df fails, pickle the object. Optionally save as csv too.
@@ -1088,12 +1089,12 @@ def dict2df(df_dict, fname, save=True, update=False, csv=False, colsort=None,
                 print('updating: %s ...' % (fname), end='')
                 try:
                     dfs.to_hdf('%s.h5' % fname, 'table', mode='r+', append=True,
-                               format='table', complevel=9, complib='blosc')
+                               format='table', complevel=9, complib=complib)
                 except IOError:
                     print('Can not update, file does not exist. Saving instead'
                           '...', end='')
                     dfs.to_hdf('%s.h5' % fname, 'table', mode='w',
-                               format='table', complevel=9, complib='blosc')
+                               format='table', complevel=9, complib=complib)
             else:
                 print('saving: %s ...' % (fname), end='')
                 if csv:
@@ -1101,7 +1102,7 @@ def dict2df(df_dict, fname, save=True, update=False, csv=False, colsort=None,
                 if xlsx:
                     dfs.to_excel('%s.xlsx' % fname, index=csv_index)
                 dfs.to_hdf('%s.h5' % fname, 'table', mode='w',
-                           format='table', complevel=9, complib='blosc')
+                           format='table', complevel=9, complib=complib)
 
             print('DONE!!\n')
 
-- 
GitLab