Proposal to change the behavior when sel or $ returns a single row

17 views
Skip to first unread message

Matthew Farrell

unread,
May 16, 2013, 11:35:48 PM5/16/13
to inca...@googlegroups.com
Currently, sel, and by extension $, have inconsistent behavior when returning a single row of a dataset. If 0 rows or 2+ rows are selected, the result is a dataset, but if 1 row is selected, the result is a vector.

(def dataset0 (dataset [:a :b :c] []))
(def dataset1 (dataset [:a :b :c] [[1 2 3]]))
(def dataset2 (dataset [:a :b :c] [[1 2 3] [4 5 6]]))
(def dataset3 (dataset [:a :b :c] [[1 2 3] [4 5 6] [7 8 9]]))

(= dataset0 ($ [] :all dataset3))
(= [1 2 3]  ($ [0] :all dataset3))
(= dataset2 ($ [0 1] :all dataset3))

(= dataset0 ($ [:not 0] :all dataset1))
(= [1 2 3]  ($ [:not 1] :all dataset2))
(= dataset2 ($ [:not 2] :all dataset3))

In both of these, and other similar cases, the behavior should be consistent:

(= dataset1 ($ [0] :all dataset3))
(= dataset1 ($ [:not 1] :all dataset2))

I have a pull request ready to go to implement this change, but I wanted to get feed back from the community as this could break existing code and requires changing one of the unit tests. https://github.com/liebke/incanter/pull/143

There is a related case, where a particular row is indexed (eg, 0 vs [0]). I don't have a strong opinion on this case, though it has been brought up before (https://groups.google.com/forum/?fromgroups#!searchin/incanter/sel/incanter/OhGYASh6V_M/HPn9JQgne4wJ)

(= [1 2 3]  ($ 0 :all dataset3))

Additionally, there is the question for columns, which have analogous behavior and for which I would make analogous arguments

(= [1 4 7] ($ :all [1] dataset3))

Alex Ott

unread,
May 17, 2013, 2:25:58 AM5/17/13
to inca...@googlegroups.com
From my point of view, this could be very useful to be consistent when working with datasets, especially when list of columns or rows is determined programmatically, and we don't know how much columns or rows will be selected as result


--
 
---
You received this message because you are subscribed to the Google Groups "Incanter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to incanter+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
With best wishes,                    Alex Ott
http://alexott.net/
Twitter: alexott_en (English), alexott (Russian)
Skype: alex.ott

david humphreys

unread,
May 17, 2013, 6:28:40 AM5/17/13
to inca...@googlegroups.com
From my point of view it would be great to be consistent, so long as there are lots of warnings in the docs :)

Alex Ott

unread,
May 19, 2013, 2:56:02 PM5/19/13
to inca...@googlegroups.com
Ok, I've just merged the pull request from Matthew

I plan to go through all open bugs & pull requests, and will cut the 1.5.0 release soon...
Reply all
Reply to author
Forward
0 new messages