Skip to content
Snippets Groups Projects
Verified Commit 27d0aa5d authored by Daniel Hornung's avatar Daniel Hornung
Browse files

FIX: More tests, more fixes.

parent 210fbc41
No related branches found
No related tags found
2 merge requests!100WIP: Filling XLSX: Seems to be working.,!99FIX: `to_table` failed on lists
Pipeline #50256 failed
...@@ -25,6 +25,7 @@ import re ...@@ -25,6 +25,7 @@ import re
import sys import sys
import caosdb as db import caosdb as db
import numpy as np
import pandas as pd import pandas as pd
...@@ -64,9 +65,14 @@ def to_table(container): ...@@ -64,9 +65,14 @@ def to_table(container):
if set([p.name for p in rec.parents]) != rts: if set([p.name for p in rec.parents]) != rts:
raise ValueError("Parents differ") raise ValueError("Parents differ")
for p in rec.get_properties(): for prop in rec.get_properties():
propname = generate_property_name(prop)
df.at[ii, generate_property_name(p)] = p.value if isinstance(prop.value, list):
if propname not in df:
df[propname] = pd.Series(dtype=object)
elif df[propname].dtype != np.dtypes.ObjectDType:
df[propname] = df[propname].astype(object)
df.at[ii, propname] = prop.value
return df return df
......
...@@ -69,10 +69,14 @@ class TableTest(unittest.TestCase): ...@@ -69,10 +69,14 @@ class TableTest(unittest.TestCase):
r1 = db.Record() r1 = db.Record()
r1.add_parent("no1") r1.add_parent("no1")
r1.add_property("p1") r1.add_property("p1")
r1.add_property("p3", value=23)
r1.add_property("p4", value=[1])
r2 = db.Record() r2 = db.Record()
r2.add_parent("no1") r2.add_parent("no1")
r2.add_property("p1") r2.add_property("p1")
r2.add_property("p2", value=[1, 2]) r2.add_property("p2", value=[20, 21])
r2.add_property("p3", value=[30, 31])
r2.add_property("p4", value=[40.0, 41.0])
c = db.Container() c = db.Container()
c.extend([r1, r2]) c.extend([r1, r2])
to_table(c) to_table(c)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment