Kaynağa Gözat

Fix bug which wouldnt add iteration number to key when flattening a list

ogert 5 yıl önce
ebeveyn
işleme
e6b5d94cd9

+ 1 - 3
cdplib/FlattenData.py

@@ -129,9 +129,7 @@ class FlattenData():
             key = incoming_key
             key = incoming_key
             if incoming_key is not None:
             if incoming_key is not None:
                 # OEBB SPECIFIC IF STATEMENT
                 # OEBB SPECIFIC IF STATEMENT
-                if type(data_list[iteration]) is dict:
-                    if 'stationsnummer' in data_list[iteration].keys() and 'stage' in data_list[iteration].keys() :
-
+                if 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'])
                         key = incoming_key + '_' + str(data_list[iteration]['stationsnummer']) + '_' + str(data_list[iteration]['stage'])
                 else:
                 else:
                     key = incoming_key + '_' + str(iteration)
                     key = incoming_key + '_' + str(iteration)

+ 3 - 2
cdplib/unit_tests/TestFlattenData.py

@@ -2,6 +2,7 @@ import unittest
 import sys
 import sys
 import os
 import os
 import pandas as pd
 import pandas as pd
+from pprint import pprint
 sys.path.append(os.getcwd())
 sys.path.append(os.getcwd())
 from cdplib.log import Log
 from cdplib.log import Log
 from cdplib.FlattenData import FlattenData
 from cdplib.FlattenData import FlattenData
@@ -34,8 +35,8 @@ class TestMongodbHandler(unittest.TestCase):
 
 
         flattened_dict = self.flattener.flatten(nested_data_dict)
         flattened_dict = self.flattener.flatten(nested_data_dict)
         flattened_list = self.flattener.flatten(nested_data_list)
         flattened_list = self.flattener.flatten(nested_data_list)
-        flattened_df = self.flattener.flatten(nested_data_df)        
-        
+        flattened_df = self.flattener.flatten(nested_data_df) 
+    
         self.assertEqual(nested_data_dict["two_levels"]["one_level"], flattened_dict.loc['two_levels_one_level', 0])
         self.assertEqual(nested_data_dict["two_levels"]["one_level"], flattened_dict.loc['two_levels_one_level', 0])
         self.assertEqual(nested_data_dict["two_levels"]["one_level"], flattened_list.loc['0_two_levels_one_level', 0])
         self.assertEqual(nested_data_dict["two_levels"]["one_level"], flattened_list.loc['0_two_levels_one_level', 0])
         self.assertEqual(nested_data_dict["two_levels"]["one_level"], flattened_df.loc[0 , 'two_levels_one_level'])
         self.assertEqual(nested_data_dict["two_levels"]["one_level"], flattened_df.loc[0 , 'two_levels_one_level'])