code.pyret.org
code.pyret.org copied to clipboard
freq-bar-chart only allows strings as input
I'm confused why freq-bar-chart only allows a list of strings as input, when it seems like any value that can be uniq-ified with a set should make sense. At the very least numbers and booleans are interesting to use in a freq-bar-chart, right?
It's documented, but frustrating, that I can't take the animals table from data-science and make a freq-bar-chart with the number of legs without stringifying them first.
https://www.pyret.org/docs/latest/chart.html#%28part._chart_from-list..freq-bar-chart%29
Implementation details: we use StringDict as a way to count frequency (for performance). That's why I impose the condition that it must be a string.
However, if we want to allow non-strings, there are a couple of issues:
-
You said: "when it seems like any value that can be uniq-ified with a set should make sense"
If we want to move to that direction, then a quadratic number of comparisons is unavoidable. Are we willing to pay the price?
-
The chart must be displayed. That means values will eventually be
tostring-ed. Let's say we have two objects whose "tostring" are the same but are not equal, will it be confusing? -
Can we assume that all elements will have the same type? If the answer is yes, then we might simply tostring every elements and use them as keys.
Adding @schanzer and @shriram, because this sounds like a technical decision that's masking a pedagogical one... Any categorical area-based chart with labeled entries (pie, bar, etc), such that multiple entries have the same label, is inherently ambiguous. So this question about unique-ifying values and tostring-ing them boils down to how much do we want to scaffold errors in using these functions...
Proposal: we use DS as a testbed, and I hack the teachpack (what's the proper pyret term?) so that freq-bar-chart runs to-string over the selected column and histogram raises an error if the column values are non-numeric. After we train teachers with this, we'll have some information to go on.
@jpolitz FWIW, this chart is totally deprecated for Bootstrap. Not sure if you need it for other audiences, but there's certainly no pressure coming from me.
@jpolitz stil want to keep this open?