brownplt / code.pyret.org

Website for serving Pyret to folks.
Other
24 stars 45 forks source link

Error message causes internal error #444

Closed schanzer closed 2 years ago

schanzer commented 2 years ago

Open https://code.pyret.org/editor#share=1CUza8tsxDscC1YUgp3FPM-52nAkLzaPy&v=5f98106 Evaluate modes(movies-table, "studio")

sorawee commented 2 years ago

Minimal program that causes the error:

builtins.raw-array-sort-nums([raw-array: "a", "b"], false)
blerner commented 2 years ago

Modes currently only works on numeric columns, as evidenced by that call to raw-array-sort-nums at https://github.com/brownplt/pyret-lang/blob/horizon/src/arr/trove/statistics.arr#L56. Making that polymorphic over sortable values should be doable, I think, but it will be slower...

schanzer commented 2 years ago

I don't need it to work on other types - throwing an error would be fine!

blerner commented 2 years ago

I'm not sure how to best give an error here; the ergonomics all are lousy.

I think the last option (either the raise or refinement version) is the fastest fix for you (and you should fix it for everything in that background code that uses t.column, so mean, median, modes, stdev, r-value etc.).

schanzer commented 2 years ago

@blerner thanks - it's really cool to see how refinements work!

Given that Pyret doesn't allow mixed-type columns, couldn't I just check the first value in the column to determine the type of the rest of the values?

blerner commented 2 years ago

I think that's likely risky: iirc, Pyret guesses what each column ought to contain, but I don't recall the heuristics it uses to do so. Checking all the values in a column is still pretty cheap, at the size of tables you're dealing with, so I'd probably just check them all.

schanzer commented 2 years ago

@blerner that's helpful, as I don't have a sense for what's going to hold up CPO. Done - thank you!