Skip to content

Commit

Permalink
Merge pull request incanter#267 from johnchapin/group_on_fix
Browse files Browse the repository at this point in the history
Follow sel :filter rename to group-on
  • Loading branch information
alexott committed Aug 20, 2014
2 parents cf45eb5 + a28ac42 commit d710e5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 5 additions & 5 deletions modules/incanter-core/src/incanter/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
returns all columns by default, can pass a column index or sequence of column indices
:except-rows (default nil) can pass a row index or sequence of row indices to exclude
:except-cols (default nil) can pass a column index or sequence of column indices to exclude
:filter (default nil)
:filter-fn (default nil)
a function can be provided to filter the rows of the matrix
Examples:
Expand All @@ -215,7 +215,7 @@
(sel iris :except-cols 1) ; all columns except the second
;; return only the first 10 even rows
(sel iris :rows (range 10) :filter #(even? (int (nth % 0))))
(sel iris :rows (range 10) :filter-fn #(even? (int (nth % 0))))
;; select rows where distance (third column) is greater than 50
(sel iris :filter #(> (nth % 2) 4))
Expand Down Expand Up @@ -1175,11 +1175,11 @@
]
(cond
cols
(map #(sel mat :cols cols :filter (filter-fn %)) groups)
(map #(sel mat :cols cols :filter-fn (filter-fn %)) groups)
except-cols
(map #(sel mat :except-cols except-cols :filter (filter-fn %)) groups)
(map #(sel mat :except-cols except-cols :filter-fn (filter-fn %)) groups)
:else
(map #(sel mat :filter (filter-fn %)) groups)))))
(map #(sel mat :filter-fn (filter-fn %)) groups)))))



Expand Down
8 changes: 8 additions & 0 deletions modules/incanter-core/test/incanter/core_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -704,3 +704,11 @@
(is (= (pow (matrix [1 2 3]) 2) (matrix [1.0 4.0 9.0])))
(is (= (pow (dataset [:a :b :c] [[1 2 3]]) 2) (dataset [:a :b :c] [[1.0 4.0 9.0]])))
)

(deftest sel-filter-test
(let [m (matrix [[110 110]])]
(is (= m (sel test-mat :filter-fn (fn [[c1 c2]] (= c1 c2)))))))

(deftest group-on-test
(let [m (matrix [[1 0] [2 1]])]
(is (= [(matrix [[1 0]]) (matrix [[2 1]])] (group-on m 1)))))

0 comments on commit d710e5e

Please sign in to comment.