Переглянути джерело

Merge branch 'master' of https://intra.acdp.at/gogs/tanja/cdplib

ogert 4 роки тому
батько
коміт
2fc52bcb80

+ 5 - 1
cdplib/db_handlers/MongodbHandler.py

@@ -343,7 +343,11 @@ class MongodbHandler:
         if len(frames) > 1:
             return_df = pd.concat(frames, axis=0, sort=False)
         else:
-            return_df = frames[0]
+            if not frames:
+                self._log.warning('Query returned empty Cursor')
+                return_df = pd.DataFrame()
+            else:
+                return_df = frames[0]
 
         if index is not None:
             return_df.set_index(index, inplace=True)

+ 7 - 2
cdplib/db_migration/MigrationCleaning.py

@@ -562,13 +562,18 @@ class MigrationCleaning:
 
         return data
 
-    def clean_json_from_None_object(self, data: pd.DataFrame) -> pd.DataFrame():
+    def clean_json_from_None_object(self, data: pd.DataFrame, clean_bool: bool = True) -> pd.DataFrame():
+        
         data = data.to_json(date_format="iso")
         data = json.loads(data)
         new_data = remap(data, lambda p, k, v: v is not None)
         new_data = remap(new_data, lambda p, k, v: v != 'None')
         new_data = remap(new_data, lambda p, k, v: v != 'inf')
-        new_data = remap(new_data, lambda p, k, v: (isinstance(v,bool) or (not isinstance(v,bool) and bool(v))))
+        # cleans not only bool type also int which are 0 or 1 
+        # only use if it is necessary have to be change that it only considers
+        # Ture and False for bools 
+        if clean_bool:
+            new_data = remap(new_data, lambda p, k, v: (isinstance(v,bool) or (not isinstance(v,bool) and bool(v))))
         return new_data
 
     def restrict_to_collection(self, data: pd.DataFrame, collection_name: str) -> pd.DataFrame: