|
@@ -27,20 +27,23 @@ class FlattenData():
|
|
|
|
|
|
assert(isinstance(data, (list, dict, pd.DataFrame))),\
|
|
assert(isinstance(data, (list, dict, pd.DataFrame))),\
|
|
"Parameter 'data' either be of List, Dictionary or DataFrame type"
|
|
"Parameter 'data' either be of List, Dictionary or DataFrame type"
|
|
-
|
|
|
|
|
|
+ in_length=0
|
|
start = time.time()
|
|
start = time.time()
|
|
if type(data) is pd.DataFrame:
|
|
if type(data) is pd.DataFrame:
|
|
|
|
+ in_length = len(data.columns)
|
|
return_data = self.flatten_dataframe(data)
|
|
return_data = self.flatten_dataframe(data)
|
|
- if type(data) is dict:
|
|
|
|
|
|
+ elif type(data) is dict:
|
|
|
|
+ in_length = len(data)
|
|
return_data = self.flatten_dict(data)
|
|
return_data = self.flatten_dict(data)
|
|
- if type(data) is list:
|
|
|
|
|
|
+ elif type(data) is list:
|
|
|
|
+ in_length = len(data)
|
|
return_data = self.flatten_list(data)
|
|
return_data = self.flatten_list(data)
|
|
else:
|
|
else:
|
|
- self._log.log_and_raise_warning('Input data type is not supported')
|
|
|
|
|
|
+ self._log.log_and_raise_warning(("Input data type '{}' is not supported").format(type(data)))
|
|
return None
|
|
return None
|
|
|
|
|
|
result_dataframe = pd.DataFrame.from_dict(return_data, orient='index')
|
|
result_dataframe = pd.DataFrame.from_dict(return_data, orient='index')
|
|
- self._log.info(('Data has been flattened, created {} columns in {} seconds').format(len(result_dataframe.columns)- len(data.columns), time.time()-start))
|
|
|
|
|
|
+ self._log.info(('Data has been flattened, created {} columns in {} seconds').format(len(result_dataframe.columns)- in_length, time.time()-start))
|
|
return result_dataframe
|
|
return result_dataframe
|
|
|
|
|
|
def flatten_dataframe(self, dataframe: pd.DataFrame, incoming_key: str = None):
|
|
def flatten_dataframe(self, dataframe: pd.DataFrame, incoming_key: str = None):
|
|
@@ -73,7 +76,7 @@ class FlattenData():
|
|
|
|
|
|
result_dict[index] = copy.deepcopy(temp_result_dict)
|
|
result_dict[index] = copy.deepcopy(temp_result_dict)
|
|
|
|
|
|
- return result_dataframe
|
|
|
|
|
|
+ return result_dict
|
|
|
|
|
|
def flatten_dict(self, dictionary: dict, incoming_key: str = None):
|
|
def flatten_dict(self, dictionary: dict, incoming_key: str = None):
|
|
'''
|
|
'''
|