diff options
Diffstat (limited to 'qolab/tableflow/__init__.py')
-rw-r--r-- | qolab/tableflow/__init__.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/qolab/tableflow/__init__.py b/qolab/tableflow/__init__.py index 8a84aca..15180ca 100644 --- a/qolab/tableflow/__init__.py +++ b/qolab/tableflow/__init__.py @@ -60,7 +60,19 @@ def ilocRowOrAdd(tbl, row): If similar 'row' not found in the table, insert it. """ tSub = tbl[row.keys()] - res = (tSub == row) | (tSub.isna() & row.isna()) + # Below loop does condition below + # res = (tSub == row) | (tSub.isna() & row.isna()) + # but NA is ambiguous so we have to spell it out + res = pd.DataFrame(data=None, columns=tSub.columns, index=tSub.index, dtype=bool) + res[:] = False + for col in row.keys(): + if pd.isna(row[col]): + res[col] = tSub[col].isna() + else: + igood = tSub[col].notna() + res.loc[igood, col] = (tSub.loc[igood, col] == row[col]) + imissing = tSub[col].isna() + res.loc[imissing, col] = False res = res.all(axis=1) # which rows coincide if res.any(): # we have a similar row |