fsprojects / IfSharp

F# for Jupyter Notebooks
Other
440 stars 71 forks source link

Util.Table: Use propertyNames for ordering of columns #252

Closed arnodenuijl closed 4 years ago

arnodenuijl commented 4 years ago

Description

When I use Util.Table and I set the propertyNames explicitly I expect the order of the columns to respect the order given with the propertyNames. I ran into this when using Util.Table with a sequence of anonymous records. The way I think it works is that typeof<'A>.GetProperties() that is used gives the properties in declared order when used on a normal type and in alphabetical order when used on an anonymous type. Since I didn't like the alphabetical ordering I searched for a way to set the ordering. When I ran into the propertyNames property I expected this to pin the order.

Repro steps

Util.Table(
    [ {|A = 5; B = 3; C = 9|} ],
    ["C"; "A"])

Expected behavior

C A
9 5

Actual behavior

A C
5 9

Known workarounds

Dont't use anonymous types?!

Related information

I reworked the Util.Table function to do what I expected it to do. https://github.com/arnodenuijl/IfSharp/commit/18fa8a1924504cf8753675fd9a919f8afe4a0b3e

If you want it as a pull request i can do that. Any questions or remarks are welcome

cgravill commented 4 years ago

Looks good to me, preserving the given order in those cases seems nice to have and any performance impact shouldn't be an issue. Please do make a pull request when convenient.

arnodenuijl commented 4 years ago

Cool. https://github.com/fsprojects/IfSharp/issues/252

arnodenuijl commented 4 years ago

Merged https://github.com/fsprojects/IfSharp/pull/253