|
@@ -62,15 +62,17 @@ class FlattenData():
|
|
'''
|
|
'''
|
|
assert(isinstance(dataframe, pd.DataFrame)),\
|
|
assert(isinstance(dataframe, pd.DataFrame)),\
|
|
"Parameter 'dataframe' be of DataFrame type"
|
|
"Parameter 'dataframe' be of DataFrame type"
|
|
- if incoming_key is not None:
|
|
|
|
- assert(isinstance(incoming_key, str)),\
|
|
|
|
- "Parameter 'incoming_key' be of String type"
|
|
|
|
|
|
+ if incoming_key is not None and not isinstance(incoming_key, str):
|
|
|
|
+ incoming_key = str(incoming_key)
|
|
|
|
+
|
|
|
|
|
|
result_dict = {}
|
|
result_dict = {}
|
|
|
|
|
|
for index, row in dataframe.iterrows():
|
|
for index, row in dataframe.iterrows():
|
|
temp_result_dict = {}
|
|
temp_result_dict = {}
|
|
for key, value in row.iteritems():
|
|
for key, value in row.iteritems():
|
|
|
|
+ if not isinstance(key, str):
|
|
|
|
+ key = str(key)
|
|
small_key = key
|
|
small_key = key
|
|
if incoming_key is not None:
|
|
if incoming_key is not None:
|
|
key = incoming_key + '_' + key
|
|
key = incoming_key + '_' + key
|
|
@@ -101,16 +103,17 @@ class FlattenData():
|
|
'''
|
|
'''
|
|
assert(isinstance(dictionary, dict)),\
|
|
assert(isinstance(dictionary, dict)),\
|
|
"Parameter 'dictionary' be of Dictionary type"
|
|
"Parameter 'dictionary' be of Dictionary type"
|
|
- if incoming_key is not None:
|
|
|
|
- assert(isinstance(incoming_key, str)),\
|
|
|
|
- "Parameter 'incoming_key' be of String type"
|
|
|
|
|
|
+ if incoming_key is not None and not isinstance(incoming_key, str):
|
|
|
|
+ incoming_key = str(incoming_key)
|
|
|
|
|
|
|
|
|
|
result_dict = {}
|
|
result_dict = {}
|
|
for key in dictionary:
|
|
for key in dictionary:
|
|
- small_key = key
|
|
|
|
-
|
|
|
|
temp_data = dictionary[key]
|
|
temp_data = dictionary[key]
|
|
|
|
+ if not isinstance(key, str):
|
|
|
|
+ key = str(key)
|
|
|
|
+
|
|
|
|
+ small_key = key
|
|
if incoming_key is not None:
|
|
if incoming_key is not None:
|
|
key = incoming_key + '_' + key
|
|
key = incoming_key + '_' + key
|
|
temp_result = {}
|
|
temp_result = {}
|
|
@@ -137,9 +140,9 @@ class FlattenData():
|
|
|
|
|
|
assert(isinstance(data_list, list)),\
|
|
assert(isinstance(data_list, list)),\
|
|
"Parameter 'data_list' be of List type"
|
|
"Parameter 'data_list' be of List type"
|
|
- if incoming_key is not None:
|
|
|
|
- assert(isinstance(incoming_key, str)),\
|
|
|
|
- "Parameter 'incoming_key' be of String type"
|
|
|
|
|
|
+ if incoming_key is not None and not isinstance(incoming_key, str):
|
|
|
|
+ incoming_key = str(incoming_key)
|
|
|
|
+
|
|
|
|
|
|
result_dict = {}
|
|
result_dict = {}
|
|
for iteration, item in enumerate(data_list):
|
|
for iteration, item in enumerate(data_list):
|
|
@@ -147,17 +150,13 @@ class FlattenData():
|
|
temp_dataframe = item
|
|
temp_dataframe = item
|
|
temp_result = {}
|
|
temp_result = {}
|
|
key = incoming_key
|
|
key = incoming_key
|
|
-
|
|
|
|
|
|
+ if not isinstance(key, str):
|
|
|
|
+ key = str(key)
|
|
|
|
+
|
|
if incoming_key is not None:
|
|
if incoming_key is not None:
|
|
- # OEBB SPECIFIC IF STATEMENT
|
|
|
|
- if type(data_list[iteration]) is dict and 'stationsnummer' in data_list[iteration].keys():
|
|
|
|
- key = incoming_key + '_' + str(data_list[iteration]['stationsnummer'])
|
|
|
|
-
|
|
|
|
- elif type(data_list[iteration]) is dict and 'stationsnummer' in data_list[iteration].keys() and 'stage' in data_list[iteration].keys() :
|
|
|
|
- key = incoming_key + '_' + str(data_list[iteration]['stationsnummer']) + '_' + str(data_list[iteration]['stage'])
|
|
|
|
|
|
|
|
- else:
|
|
|
|
- key = incoming_key + '_' + str(iteration)
|
|
|
|
|
|
+ list_iterator = add_list_iterator(data_list, iteration)
|
|
|
|
+ key = incoming_key + '_' + list_iterator
|
|
else:
|
|
else:
|
|
key = str(iteration)
|
|
key = str(iteration)
|
|
if type(temp_dataframe) == list:
|
|
if type(temp_dataframe) == list:
|
|
@@ -196,4 +195,9 @@ class FlattenData():
|
|
return self.flatten(data, labels_to_ignore=labels_to_ignore)
|
|
return self.flatten(data, labels_to_ignore=labels_to_ignore)
|
|
|
|
|
|
return data
|
|
return data
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ # Create class that inherits FlattenData and overwrite this function for specific implementations.
|
|
|
|
+ def add_list_iterator(self, data_list: list, iteration: int):
|
|
|
|
+ return str(iteration)
|
|
|
|
|