Skip to content

Commit

Permalink
check for ind column value checks
Browse files Browse the repository at this point in the history
  • Loading branch information
acutesoftware committed May 15, 2017
1 parent 80d40a0 commit 2930324
Showing 1 changed file with 41 additions and 15 deletions.
56 changes: 41 additions & 15 deletions scripts/examples/table_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,8 @@

import cls_datatable as cl


with open('dummy_table1.csv', "w") as f:
f.writelines(
"""TERM,GENDER,ID,tot1,tot2,tot3
5300,F,00078,18,66,45
7310,M,00078,16,465,64
7310,F,00078,30,2,3
7310,F ,00016,25,12,2
5320,M,00016,31,0,66
7310,F,00016,67,873,2""")

with open('dummy_table2.csv', "w") as f:
f.writelines(
"""TERM,Gender,ID,tot1,tot2
5300,F,00078,18,66
7310,M,00078,18,465
Expand All @@ -33,6 +22,17 @@
5300,M,00016,31,0
7310,F,00016,67,873""")

with open('dummy_table2.csv', "w") as f:
f.writelines(
"""TERM,GENDER,ID,tot1,tot2,tot3
5300,F,00078,18,66,45
7310,M,00078,16,465,64
7310,F,00078,30,2,3
7310,F ,00016,25,12,2
5320,M,00016,31,0,66
7310,F,00016,67,873,2""")


old_table = 'dummy_table1.csv'
new_table = 'dummy_table2.csv'

Expand All @@ -59,23 +59,33 @@ def main():

print('Comparing tables ' )

print(check_col_names(t_old, t_new))
print(check_rows(t_old, t_new))
res, pass_fail = check_col_names(t_old, t_new)
print(res)
if pass_fail != 'OK':
print('Bypassing exact row test, as columns are different')
else:
print(check_rows(t_old, t_new))

res, pass_fail = compare_values(t_old, t_new)
print(res)




def check_col_names(t_old, t_new):
res = '\n -- Column Name check -- \n'

pass_fail = 'OK'
for col_num, c in enumerate(t_old.header):
if len(t_new.header) >= col_num + 1:
if c == t_new.header[col_num]:
res += c + ' ok\n'
else:
res += c + ' different name (now ' + t_new.header[col_num] + ')\n'
pass_fail = 'Different Name'
else:
res += c + ' is missing in new table\n'
return res
pass_fail = 'Missing Column'
return res, pass_fail


def check_rows(t_old, t_new):
Expand All @@ -91,6 +101,22 @@ def check_rows(t_old, t_new):
res += r + ' is missing in new table\n'
return res

def compare_values(t_old, t_new):
res = '\n -- compare_values -- \n'
pass_fail = 'OK'

for row_num, r in enumerate(t_old.arr):
if len(t_new.arr) >= row_num + 1:
for col_num, c in enumerate(r):
if c == t_new.arr[row_num][col_num]:
#res += c + ' ok\n'
pass
else:
res += ' different value in [' + str(row_num) + '][' + str(col_num) + '] was ' + c + ' => ' + t_new.arr[row_num][col_num] + '\n'
pass_fail = 'Different value'

return res, pass_fail



if __name__ == '__main__':
Expand Down

0 comments on commit 2930324

Please sign in to comment.