aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugeniy E. Mikhailov <evgmik@gmail.com>2024-06-02 23:05:41 -0400
committerEugeniy E. Mikhailov <evgmik@gmail.com>2024-06-02 23:05:41 -0400
commit605238126fe5f99d69b0de3f5278ff83f21349b6 (patch)
tree6d15d11cb15f14c90f22a48e7e8db7dafbc62c77
parentd32aaa6bce0eacd5d6ee919a239c7aaad606fc23 (diff)
downloadqolab-605238126fe5f99d69b0de3f5278ff83f21349b6.tar.gz
qolab-605238126fe5f99d69b0de3f5278ff83f21349b6.zip
more test cases and bugfixes in tableflow
-rw-r--r--qolab/tableflow/__init__.py2
-rw-r--r--tests/test_tableflow.py32
2 files changed, 33 insertions, 1 deletions
diff --git a/qolab/tableflow/__init__.py b/qolab/tableflow/__init__.py
index 2a150a8..1466dde 100644
--- a/qolab/tableflow/__init__.py
+++ b/qolab/tableflow/__init__.py
@@ -81,7 +81,7 @@ def reflowTable(tIn, tOut, process_row_func=None, postProcessedColums=None, extr
iOut = ilocRowOrAdd(tOut, rowIn)
rowOutBefore = tOut.iloc[iOut]
- if not (redo or isRedoNeeded(rowOut, postProcessedColums) ):
+ if not (redo or isRedoNeeded(rowOutBefore, postProcessedColums) ):
continue
# processing data describing row
diff --git a/tests/test_tableflow.py b/tests/test_tableflow.py
index fce3449..fd52525 100644
--- a/tests/test_tableflow.py
+++ b/tests/test_tableflow.py
@@ -78,7 +78,39 @@ def test_isRedoNeeded():
def test_reflowTable():
tIn,tOut = tblfl.loadInOutTables(inputFileName='tests/tableflow_test_data/tableIn1.csv', outputFileName='tests/tableflow_test_data/tableOut1pariallyProcessed.csv', comment='#')
tOutRef = tOut.copy()
+ # check for warnings
with pytest.warns(UserWarning):
tblfl.reflowTable(tIn,tOut)
+ with pytest.warns(UserWarning):
+ tblfl.reflowTable(tIn,tOut,postProcessedColums=['dummyName'])
+
+ def frow(row):
+ return row
+ with pytest.warns(UserWarning):
+ tblfl.reflowTable(tIn,tOut, process_row_func=frow)
+
+ # now run reflow
+ def frow(row, extraInfo=None):
+ row['out1'] = row['x']*row['x']
+ return row
+ assert len(tIn) != len(tOut)
+ tblfl.reflowTable(tIn,tOut, process_row_func=frow, postProcessedColums=['out1','out2'])
+ assert len(tIn) == len(tOut)
+ assert (tOut['out1'] == tOut['x']*tOut['x']).all()
+
+ # check that reflow is done
+ tOut.loc[tOut['x']==1, 'out1'] = pd.NA
+ tblfl.reflowTable(tIn,tOut, process_row_func=frow, postProcessedColums=['out1','out2'])
+ assert (tOut['out1'] == tOut['x']*tOut['x']).all()
+
+ # check that reflow is not reprocessed
+ tOut.loc[tOut['x']==1, 'out1'] = 12121 # crazy number
+ tblfl.reflowTable(tIn,tOut, process_row_func=frow, postProcessedColums=['out1','out2'])
+ assert (tOut.loc[tOut['x']==1, 'out1'] == 12121).all() # should not change
+ # now we are forcing redo
+ tOut.loc[tOut['x']==1, 'out1'] = 12121 # crazy number
+ tblfl.reflowTable(tIn,tOut, process_row_func=frow, postProcessedColums=['out1','out2'], redo=True)
+ assert not (tOut.loc[tOut['x']==1, 'out1'] == 12121).all() # must not be the same
+ assert (tOut['out1'] == tOut['x']*tOut['x']).all()