aboutsummaryrefslogtreecommitdiff
path: root/qolab/tableflow/__init__.py
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2024-07-14 21:14:12 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2024-07-14 21:14:12 -0400
commit9d04581bf9a1a5de39b92e2e27fe0248edcf2a5e (patch)
treef86020f311cdc7bf287d1af768e41dc731161168 /qolab/tableflow/__init__.py
parent5bf85c8f23d7c0a505fc62499658e82fbd641d9b (diff)
downloadqolab-9d04581bf9a1a5de39b92e2e27fe0248edcf2a5e.tar.gz
qolab-9d04581bf9a1a5de39b92e2e27fe0248edcf2a5e.zip
fixed depreciation warning and make it future proof
Diffstat (limited to 'qolab/tableflow/__init__.py')
-rw-r--r--qolab/tableflow/__init__.py14
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