Commit f262f09c authored by Nic's avatar Nic
Browse files

to_configobj now handles units

parent c97ea8a3
......@@ -250,6 +250,14 @@ class IOMixin:
if not fpath:
config.filename = None
for tabname, df in self._data.items():
try:
units = self.getunits(tabname)
except KeyError:
units = {}
if units:
# insert units row
units = pd.Series(units).to_frame().T
df = pd.concat((units, df), ignore_index=True)
df = df.fillna("")
df2dict = df.T.to_dict()
config[tabname] = {} # create a section
......
......@@ -683,6 +683,23 @@ def test_IVData_06_units(datadir):
)
diff = l9_quantity - l9_quantity_exp
assert abs(diff.magnitude) < 1e-5
# -------------------------------------------------------------------------
# to_configobj
co = data_imp.to_configobj()
new_data = IVData()
new_data.read_configobj(co)
new_data.read_schema(
os.path.join(indir, "test_04_IMP.yaml"),
os.path.join(indir, "test_04_data.yaml"),
)
new_data.validate()
assert new_data.getunits("pressure", key="test_p_bar") == "psi"
for tabname in data_imp._data:
df_imp = data_imp.convert_to(tabname) # .pint.to_base_units()
df_new_data = new_data.convert_to(tabname) # .pint.to_base_units()
exp = df_imp.pint.dequantify()
act = df_new_data.pint.dequantify()
assert pd.testing.assert_frame_equal(exp, act) is None
def test_IVData_07_failing_units(datadir):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment