Skip to content

Commit ce870a5

Browse files
authored
Merge pull request #205 from behrica/fixAsDoubleArray
fix :as-double-array with "nan+nil"
2 parents 7bb142d + 247a6b0 commit ce870a5

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

src/tablecloth/api/dataset.clj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
[tech.v3.dataset.print :as p]
1010
[tech.v3.dataset.protocols :as prot]
1111
[tech.v3.dataset.tensor :as ds-tensor]
12-
[tech.v3.tensor :as tensor])
12+
[tech.v3.tensor :as tensor]
13+
[ham-fisted.api :as hf])
1314
(:import
1415
[java.io FileNotFoundException]))
1516

@@ -156,7 +157,7 @@
156157
(let [cols (ds/columns ds)]
157158
(case result-type
158159
:as-map (zipmap (ds/column-names ds) cols)
159-
:as-double-arrays (into-array (map double-array (ds/columns ds)))
160+
:as-double-arrays (into-array (map (fn [row] (hf/double-array row)) (ds/columns ds)))
160161
:as-seqs cols
161162
cols))))
162163

@@ -177,7 +178,7 @@
177178
(let [options (assoc options :nil-missing? nil-missing?)]
178179
(case result-type
179180
:as-maps (ds/mapseq-reader ds options)
180-
:as-double-arrays (into-array (map double-array (ds/value-reader ds)))
181+
:as-double-arrays (into-array (map (fn [row] (hf/double-array row)) (ds/value-reader ds)))
181182
:as-seqs (ds/value-reader ds options)
182183
:as-vecs (ds/rowvecs ds options)
183184
(ds/value-reader ds options)))))

test/tablecloth/api/dataset_test.clj

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
[tablecloth.column.api :as tcc]
77
[tablecloth.common-test :refer [DS]]
88
[tech.v3.libs.arrow :as arrow]
9-
[tech.v3.libs.fastexcel :as fastexcel]
10-
[tablecloth.api :as tc])
9+
[tech.v3.libs.fastexcel :as fastexcel])
1110
(:import
1211
[java.io FileNotFoundException]))
1312

@@ -126,15 +125,34 @@
126125
{:name :V4, :n-elems 9, :categorical? true, :datatype :string}]))
127126

128127
(fact "as-double-arrays"
129-
(tabular (fact (-> (api/dataset {:a [1 2 3]
130-
:b [5 6 7]})
131-
(?f :as-double-arrays)
132-
(->> (map seq)))
133-
= ?v)
128+
(tabular (fact
129+
(-> (api/dataset {:a [1 2 3]
130+
:b [5 6 7]})
131+
(?f :as-double-arrays)
132+
(->> (map seq)))
133+
=> ?v)
134134
?f ?v
135135
api/rows '((1.0 5.0) (2.0 6.0) (3.0 7.0))
136136
api/columns '((1.0 2.0 3.0) (5.0 6.0 7.0))))
137137

138+
(fact "as-double-arrays--nil/nan"
139+
(let [rows
140+
(->
141+
(api/dataset {:a [1.0 nil 3.0]
142+
:b [Double/NaN 5.0 7.0]})
143+
(api/rows :as-double-arrays))
144+
cols
145+
(->
146+
(api/dataset {:a [1.0 nil 3.0]
147+
:b [Double/NaN 5.0 7.0]})
148+
(api/columns :as-double-arrays))]
149+
150+
(-> rows first second Double/isNaN) => true
151+
(-> rows second first Double/isNaN) => true
152+
(-> cols first second Double/isNaN) => true
153+
(-> cols second first Double/isNaN) => true))
154+
155+
138156
(fact "let-dataset"
139157
(fact (api/let-dataset [x (range 4) y 10 z (tcc/+ x y)])
140158
=> (api/dataset {:x [0 1 2 3]

0 commit comments

Comments
 (0)