Skip to content

Commit

Permalink
Fix parsing of doubles to conform to xsd:double spec
Browse files Browse the repository at this point in the history
  • Loading branch information
RickMoynihan committed Jan 25, 2024
1 parent d2e1eaf commit 3543ece
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Year,Double,Other Double,Comment
1980,100.10,11.0,this row is ok
1980,101,12.0,this row has a number without a decimal in 2nd column
1980,nan,12.0,this row has an invalid xsd:double NaN literal in it
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Year,Double,Other Double,Comment
1999,100,10.0,this row has a double without a decimal point
1999,nan,10.0,this row has an incorrectly formatted xsd:double NaN value in it
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@
(defn parse-double*
"Returns a double or nil."
[v]
(XMLDatatypeUtil/parseDouble v))
(try
(XMLDatatypeUtil/parseDouble v)
(catch NumberFormatException ex
nil)))

(defn- datatype+parse-fn
"Returns a tuple of [datatype parse-fn] as required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@
(let [ex (try (data.validation/as-dataset csv {:enforce-schema row-schema})
(catch clojure.lang.ExceptionInfo ex
ex))]
(is (= {"Double" ["100"]} (:error-samples (ex-data ex))))))))))
(is (= {"Double" ["nan"]} (:error-samples (ex-data ex))))))))))

0 comments on commit 3543ece

Please sign in to comment.