Skip to content

Commit 2ed6402

Browse files
committed
Merge branch 'master' of github.com:techascent/tech.ml.dataset
2 parents 2e14d77 + 148c028 commit 2ed6402

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

src/tech/v3/dataset/rolling.clj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,13 @@ test/data/stocks.csv [5 6]:
270270
| AMZN | 2000-01-01 | 64.56 | 60.09222222 | 106.11 | 28.66 |
271271
| AAPL | 2000-02-01 | 28.66 | 57.56583333 | 106.11 | 28.37 |
272272
```"
273-
([ds window reducer-map _options]
273+
([ds window reducer-map options]
274274
(let [n-rows (ds-base/row-count ds)
275-
window-data (if (integer? window)
276-
{:window-size window
277-
:relative-position :center
278-
:window-type :fixed}
279-
window)
275+
window-data (merge (if (integer? window)
276+
{:window-size window
277+
:window-type :fixed}
278+
window)
279+
options)
280280
windows
281281
(case (:window-type window-data :fixed)
282282
:fixed

test/tech/v3/dataset_test.clj

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@
18021802
(deftest clone-causes-filter-fail
18031803
(let [ds (-> (ds/->dataset "test/data/stocks.csv" {:key-fn keyword})
18041804
(ds/filter (fn [row]
1805-
(and
1805+
(and
18061806
(.isAfter ^LocalDate (get row :date) (LocalDate/parse "2009-06-01"))
18071807
(= (get row :symbol) "AMZN")))))]
18081808
(is (= (vec (:date ds))
@@ -1818,8 +1818,42 @@
18181818
:age nil}])
18191819
(ds/replace-missing [:age] :value 100)
18201820
(ds/column :age)
1821-
vec)))
1822-
)
1821+
vec))))
1822+
1823+
(defn rolling-off-edge-fn
1824+
[]
1825+
(let [ds-fn (fn [relative-window-position]
1826+
(-> (ds/->dataset {:x (concat (repeat 20 1)
1827+
(repeat 20 0))})
1828+
(ds-roll/rolling 10 {:mean-x (ds-roll/mean :x)} {:relative-window-position relative-window-position})
1829+
(ds/print-all)))]
1830+
(is (not= (ds-fn :left)
1831+
(ds-fn :center)))
1832+
(is (not= (ds-fn :center)
1833+
(ds-fn :right)))
1834+
(is (not= (ds-fn :left)
1835+
(ds-fn :right)))))
1836+
1837+
(deftest rolling-off-edge
1838+
(rolling-off-edge-fn))
1839+
1840+
(defn stacked-rolling-fn
1841+
[]
1842+
(let [ds0 (-> (ds/->dataset {:y (repeat 20 2)
1843+
:x (range)
1844+
:t 0})
1845+
(ds-roll/rolling 10 {:mean-y (ds-roll/mean :y)} {:relative-window-position :left}))
1846+
ds1 (-> (ds/->dataset {:y (repeat 40 1)
1847+
:x (range)
1848+
:t 1})
1849+
(ds-roll/rolling 10 {:mean-y (ds-roll/mean :y)} {:relative-window-position :left}))
1850+
ds (-> (ds/concat ds0 ds1)
1851+
(ds/print-all))]
1852+
;; HH: 2025-09-08 - My condolences if this fails on your architecture
1853+
(is (every? #{1.0 2.0} (:mean-y ds)))))
1854+
1855+
(deftest stacked-rolling
1856+
(stacked-rolling-fn))
18231857

18241858
(comment
18251859
(require '[criterium.core :as crit])

0 commit comments

Comments
 (0)