From e5abe117d6675bed0d8b9af246149ef124ce49c5 Mon Sep 17 00:00:00 2001
From: perezgonzalez-irene <iregon@noc.ac.uk>
Date: Wed, 4 Mar 2020 10:47:34 +0000
Subject: [PATCH] Object to numeric: translate right spaces to rigth zeros

---
 common/converters.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/common/converters.py b/common/converters.py
index dc27550..a9a1558 100644
--- a/common/converters.py
+++ b/common/converters.py
@@ -1,4 +1,5 @@
 import pandas as pd
+import numpy as np
 
 from .. import properties
 
@@ -33,8 +34,12 @@ class df_converters():
         self.numeric_scale = 1. if self.dtype in properties.numpy_floats else 1
         self.numeric_offset = 0. if self.dtype in properties.numpy_floats else 0
     def object_to_numeric(self, data, scale = None, offset = None):
+        
         scale = scale if scale else self.numeric_scale
         offset = offset if offset else self.numeric_offset
+        # First do the appropriate managing of white spaces, to the right, they mean 0!
+        data = data.replace(r'^\s*$', np.nan, regex=True)
+        data = data.str.replace(' ', '0')
         #  Convert to numeric, then scale (?!) and give it's actual int type
         data = pd.to_numeric(data,errors = 'coerce') # astype fails on strings, to_numeric manages errors....!
         data = offset + data * scale
-- 
GitLab