Kotlin / kotlin-jupyter

Kotlin kernel for Jupyter/IPython
Apache License 2.0
1.11k stars 107 forks source link

Display list of data classes as table #294

Closed mwisnicki closed 3 years ago

mwisnicki commented 3 years ago

A list of data classes should be rendered as a table like the DataFrame rather than simple toString()

mwisnicki commented 3 years ago

This gets me close to what I want (although columns are ordered lexicographically rather than as defined in data class constructor) but IMHO should be default behavior:

%use krangl
someListOfDataClasses.asDataFrame()
altavir commented 3 years ago

This one will require a compiler plugin since it is not possible to decompose a generic data class (or any other class) without it. It could be done with a serialization plugin and would work for and any class marked as @Serializable.

ileasile commented 3 years ago

@mwisnicki You can achive the same thing using dataframe library. But I don't think it should be a default behaviour

ileasile commented 3 years ago

@altavir in case of data classes (which we can check in RT with KClass<*>.isData) all the constructor arguments are properties, and we can get all constructor arguments in the proper order: KClass<*>.primaryConstructor?.parameters. Some properties that are not present in primary constructor have a chance to stay unordered but it is generally acceptable

ileasile commented 3 years ago

I will close this issue. I've created the issue in dataframe about this problem: https://github.com/Kotlin/dataframe/issues/32