From 9d04581bf9a1a5de39b92e2e27fe0248edcf2a5e Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Sun, 14 Jul 2024 21:14:12 -0400 Subject: fixed depreciation warning and make it future proof --- qolab/tableflow/__init__.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'qolab') 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 -- cgit v1.2.3