makes representation of NaNs (no values) symmetric with creation- nil

This commit is contained in:
Ben Mabey 2011-04-05 13:38:10 -06:00
parent a83e21d72b
commit 7357a720e9
2 changed files with 11 additions and 8 deletions

View file

@ -313,10 +313,13 @@ If the class is nominal then the string value (not keyword) is returned."
"Returns the value of an instance attribute. A string, not a keyword is returned."
[^Instance instance pos]
(let [pos (int pos)
attr (.attribute instance pos)]
attr (.attribute instance pos)
val (.value instance pos)]
(if (Double/isNaN val)
nil
(if (.isNominal attr) ; This ignores the fact that weka can have date and other attribute types...
(.stringValue instance pos)
(.value instance pos))))
val))))
(defn instance-to-list
"Builds a list with the values of the instance"

View file

@ -127,11 +127,11 @@
(deftest working-sequences-and-helpers
(let [ds (make-dataset "test" [:a :b {:c [:d :e]}] [{:a 1 :b 2 :c :d} [4 5 :e]])]
(let [ds (make-dataset "test" [:a :b {:c [:d :e]}] [{:a 1 :b 2 :c nil} [4 nil :e]])]
(is (= 2 (dataset-count ds)))
(is (= [{:a 1 :b 2 :c "d"} {:a 4 :b 5 :c "e"}] (dataset-as-maps ds)))
(is (= [[1 2 "d"] [4 5 "e"]] (dataset-as-vecs ds)))
(is (= [{:a 1 :b 2 :c "d"} {:a 4 :b 5 :c "e"}] (map #(instance-to-map %1) (dataset-seq ds))))))
(is (= [{:a 1 :b 2 :c nil} {:a 4 :b nil :c "e"}] (dataset-as-maps ds)))
(is (= [[1 2 nil] [4 nil "e"]] (dataset-as-vecs ds)))
(is (= [{:a 1 :b 2 :c nil} {:a 4 :b nil :c "e"}] (map #(instance-to-map %1) (dataset-seq ds))))))
(deftest dataset-instance-predicates
(let [ds (make-dataset "test" [:a :b {:c [:d :e]}] [{:a 1 :b 2 :c :d} [4 5 :e]])