]> gitweb.fluxo.info Git - csv-hasher.git/commitdiff
Fix: handle KeyError
authorSilvio Rhatto <rhatto@riseup.net>
Thu, 28 Jan 2021 19:17:56 +0000 (16:17 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Thu, 28 Jan 2021 19:17:56 +0000 (16:17 -0300)
csv-hasher.py

index e3f71e5027b66bdf8e7ccad49ef4c9771628b85b..fe206f81e493a5451159c4890920b4aaaed5f7e2 100755 (executable)
@@ -106,7 +106,11 @@ class CsvHasher:
             df.columns = sample.columns
 
             # Hashing the column
-            df[self.args.colname[0]] = self.apply_hash(df)
+            try:
+                df[self.args.colname[0]] = self.apply_hash(df)
+            except KeyError as e:
+                print('Column not found: ' + self.args.colname[0])
+                exit (1)
 
             # Writing the new CSV output
             df.to_csv(self.args.outfile[0], index=False, mode='a', header=write_header)