Repository navigation
Description
Part of #90 (PR #61 catch-up), recovered by the triage correction.
What is missing
Neither readtablechar nor writetablechar exists in Python. On main, readtablechar appears only as an entry in src/ndi/ndi_matlab_python_bridge_database_fun.yaml — there is no implementation:
$ git grep -in "readtablechar\|writetablechar" origin/main -- 'src/**/*.py'
(nothing)
MATLAB has both — +ndi/+database/+fun/readtablechar.m and writetablechar.m. #90 recorded readtablechar as present at the fork point; it was not, and it still is not.
The consequence is visible in a ported function today
NDI stores small tables (mixture / odor / treatment) as delimited-text char arrays inside documents. MATLAB's +ndi/+fun/+docTable/treatment.m:110 reads one back and expands it into three derived columns:
if strcmp(fn{f},'mixture_table')
mixtureTable = ndi.database.fun.readtablechar(val,'.txt','Delimiter',',');
treatmentRow.DrugTreatmentMixtureName = mixtureTable.name;
treatmentRow.DrugTreatmentMixtureQuantity = cellstr(compose("%g %s", ...
mixtureTable.value, mixtureTable.unitName{1}));
treatmentRow.DrugTreatmentMixtureOntology = mixtureTable.ontologyName;
if options.hideMixtureTable
indSkip(f) = true;
continue
end
endNote the ordering: the three DrugTreatmentMixture* columns are produced unconditionally. hideMixtureTable only controls whether the raw mixture_table column is also dropped.
Python's fun/doc_table.py:512 takes the same hideMixtureTable parameter but never parses anything — it just drops columns by name:
if hideMixtureTable:
mixture_cols = [c for c in table.columns if "Mixture" in c or "mixture" in c]
if mixture_cols:
table = table.drop(columns=mixture_cols)git grep -c DrugTreatmentMixture finds zero hits in src/ on main. So the Python table is missing three columns MATLAB always produces, and hideMixtureTable=False does not restore them — it just stops hiding a column that was never expanded.
+ndi/+fun/+docTable/epoch.m:108 reads a mixture table the same way, so check that one too.
Scope
Two pieces, and the second is the one that actually fixes anything:
- Port
readtablecharandwritetablechar. The branchcatchup/ndi-python-2026-08hasreadtablecharinsrc/ndi/database_fun.py, parsing to apandas.DataFrameand mapping the readtable name-value options NDI uses (Delimiter→sep,ReadVariableNames→header), accepting them MATLAB-style as positional pairs or as keywords. It does not havewritetablechar— that still needs writing, and it is what produces the char arrays in the first place, so the round trip is untested without it. - Fix the callers. The branch does not have the
DrugTreatmentMixture*columns either (git grep -cis zero there too), so portingreadtablecharalone leavesdoc_table.treatmentanddoc_table.epochstill wrong. This is the part with user-visible effect.
Verification
MATLAB's own docstring gives the round-trip test almost verbatim:
t = array2table(rand(10,3))
c = ndi.database.fun.writetablechar(t,'Delimiter','\t','WriteVariableNames',false);
t2 = ndi.database.fun.readtablechar(c,'.txt','Delimiter','\t');
all(abs(t{:,:}-t2{:,:}) < 1e-15)Plus a symmetry case: a mixture_table char array written by MATLAB, read in Python, asserting the three derived columns match. That is the test that would have caught this.
Activity