@@ -600,30 +600,41 @@ test/data/stocks.csv [10 3]:
600600
601601(defn- update-values
602602 [col missing scalar-val]
603- (if (== 0 (dtype/ecount missing))
604- col
605- (let [col (Column. (bitmap/->bitmap )
606- (dtype/clone (ds-proto/column-buffer col))
607- (meta col) nil )]
608- (reduce (hamf-rf/long-accumulator
609- data idx (.writeObject ^Buffer data idx scalar-val) data)
610- (dtype/->buffer col)
611- missing)
612- col)))
603+ (let [missing (bitmap/->bitmap missing)]
604+ (if (.isEmpty missing)
605+ col
606+ (let [cbuf (dtype/->buffer (ds-proto/column-buffer col))
607+ col-dt (dtype/elemwise-datatype col)
608+ ec (.lsize cbuf)]
609+ (Column. (bitmap/->bitmap )
610+ (dtype/make-reader-fn
611+ col-dt col-dt ec
612+ (case (casting/simple-operation-space col-dt)
613+ :int64 (let [sv (long scalar-val)]
614+ (hamf-fn/long-unary-operator
615+ idx
616+ (if (.contains missing idx)
617+ sv
618+ (.readLong cbuf idx))))
619+ :float64 (let [sv (double scalar-val)]
620+ (hamf-fn/long->double
621+ idx
622+ (if (.contains missing idx)
623+ sv
624+ (.readDouble cbuf idx))))
625+ (hamf-fn/long->obj
626+ idx
627+ (if (.contains missing idx)
628+ scalar-val
629+ (.readObject cbuf idx)))))
630+ (meta col) nil )))))
613631
614632
615633(defn replace-missing-value
616634 ([dataset filter-fn-or-ds scalar-value]
617635 (update-columnwise dataset filter-fn-or-ds
618636 (fn [col]
619- (let [missing (ds-col/missing col)]
620- (if (.isEmpty missing)
621- col
622- (ds-col/new-column
623- (:name (meta col))
624- (update-values col missing scalar-value)
625- (meta col)
626- (bitmap/->bitmap )))))))
637+ (update-values col (missing col) scalar-value))))
627638 ([dataset scalar-value]
628639 (replace-missing-value dataset identity scalar-value)))
629640
0 commit comments