From 688782dcb205dfb56f74e024df1bbee6c977c50e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Thu, 13 Apr 2023 14:01:30 +0100 Subject: [PATCH] Owl_io.head: avoid log message about assertion failure on large CSV file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Executing `Owl_dataframe.of_csv "large.csv"` prints: ``` 2023-04-13 14:01:52.922 WARN : Owl_io.head: ignored exception File "src/base/misc/owl_io.ml", line 138, characters 9-15: Assertion failed ``` Using assertions for control-flow (early exit of loop) seems wrong, and causes log messages to be shown on the console. Raise an [End_of_file] exception instead which will be handled by the iteration function just as if the file ended early. Use [raise_notrace] because the exception is immediately caught and we don't need a backtrace. Signed-off-by: Edwin Török --- src/base/misc/owl_io.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/misc/owl_io.ml b/src/base/misc/owl_io.ml index 78e5b9784..0497b8f22 100644 --- a/src/base/misc/owl_io.ml +++ b/src/base/misc/owl_io.ml @@ -135,7 +135,7 @@ let head n fname = (try iteri_lines_of_file (fun i s -> - assert (i < n); + if i >= n then raise_notrace End_of_file; Owl_utils.Stack.push lines s) fname with