code.pyret.org icon indicating copy to clipboard operation
code.pyret.org copied to clipboard

freq-bar-chart only allows strings as input

Open jpolitz opened this issue 7 years ago • 5 comments

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

jpolitz avatar Jun 29 '18 13:06 jpolitz

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:

  1. 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?

  2. 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?

  3. 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.

sorawee avatar Jun 29 '18 14:06 sorawee

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...

blerner avatar Jul 07 '18 14:07 blerner

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.

schanzer avatar Jul 25 '18 16:07 schanzer

@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.

schanzer avatar Nov 22 '20 20:11 schanzer

@jpolitz stil want to keep this open?

schanzer avatar Jan 11 '24 15:01 schanzer