Commit 73596b88 authored by Irene Perez Gonzalez's avatar Irene Perez Gonzalez
Browse files

Changes following use of pandas nullable integers

parent 6b4baf21
import numpy as np import numpy as np
import pandas as pd
import string import string
from .. import properties from .. import properties
...@@ -60,28 +61,16 @@ class df_decoders(): ...@@ -60,28 +61,16 @@ class df_decoders():
self.dtype = dtype if dtype in properties.numeric_types else 'object' self.dtype = dtype if dtype in properties.numeric_types else 'object'
def signed_overpunch(self, data ): def signed_overpunch(self, data ):
decoded_numeric = np.vectorize(signed_overpunch_i,otypes=[float])(data) decoded_numeric = np.vectorize(signed_overpunch_i,otypes=[float])(data)
try: return pd.Series(decoded_numeric,dtype = self.dtype)
return decoded_numeric.astype(self.dtype, casting = 'safe')
except:
return decoded_numeric
def base36(self, data): def base36(self, data):
# int(str(np.nan),36) ==> 30191 # Caution: int(str(np.nan),36) ==> 30191
# Had to do the following because the astype() below did not seem to convert
# to object element-wise, but the full thing. As a result, str methods
# in converters from objects originating here were failing: the column
# was dtype = 'object', but the elements inside where 'int'....
# Checked that manually a seemed to be happening that way....
if self.dtype == 'object' : if self.dtype == 'object' :
base10 = np.array([str(int(str(i), 36)) if i == i and i else np.nan for i in data ]) base10 = [ str(int(str(i), 36)) if i == i and i else np.nan for i in data ]
else: else:
base10 = np.array([int(str(i), 36) if i == i and i else np.nan for i in data ]) base10 = [ int(str(i), 36) if i == i and i else np.nan for i in data ]
try: return pd.Series(base10,dtype = self.dtype)
return base10.astype(self.dtype, casting = 'safe')
except:
return base10
decoders = dict() decoders = dict()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment