From ed669630c6c404cce923975198e29e25bc95d86d Mon Sep 17 00:00:00 2001 From: Drew Frank Date: Thu, 11 Oct 2012 15:07:24 -0700 Subject: [PATCH] python: process result files after metadata type inference. --- src/optional/python/gnuparallel/_loader.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/optional/python/gnuparallel/_loader.py b/src/optional/python/gnuparallel/_loader.py index 24a6ca6a..afee6a64 100755 --- a/src/optional/python/gnuparallel/_loader.py +++ b/src/optional/python/gnuparallel/_loader.py @@ -101,9 +101,6 @@ def load(_dir, _process=None, _format=None, _stream='stdout', # Create a DataFrame from the matches. df = pd.DataFrame(matches) - if _process and not df.empty: - df['res'] = df.resfile.apply(_process) - df = df.drop('resfile', axis=1) # Optionally try to convert string argument values to numeric types. if _infer_types: @@ -111,6 +108,13 @@ def load(_dir, _process=None, _format=None, _stream='stdout', df.to_csv(buf) df = pd.read_csv(StringIO(buf.getvalue()), index_col=0) + # Open and process the results. This needs to happen after the type + # infererence phase since the processed results can be arbitrary + # Python objects and might not survive the round-trip. + if _process and not df.empty: + df['res'] = df.resfile.apply(_process) + df = df.drop('resfile', axis=1) + return df def _parse_name(file, sep='\t'):