Add DataFrame.renderToMarkdown(): String function#1760
Add DataFrame.renderToMarkdown(): String function#1760
Conversation
What kind of quirks do you mean? |
core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/string.kt
Outdated
Show resolved
Hide resolved
| val expected = | ||
| """ | ||
| | | name | age | city | | ||
| |---:|---:|---:|---:| |
There was a problem hiding this comment.
what do these colons do? I don't think I've seen them before in MD tables
There was a problem hiding this comment.
ah! it's alignment, right? Uhm, maybe we should have "no alignment" as an option, as well as right/left alignment. There are some right-to-left languages that could cause issues with a default alignment. (Actually, they probably already break tables like these, they broke our toString() very much too)
There was a problem hiding this comment.
could we still have a "no-alignment" option?
There was a problem hiding this comment.
sure! it's still in progress, i'll update once more after review
core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/string.kt
Outdated
Show resolved
Hide resolved
core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/string.kt
Outdated
Show resolved
Hide resolved
| val decimalFormat = | ||
| if (precision >= 0) RendererDecimalFormat.fromPrecision(precision) else RendererDecimalFormat.of("%e") | ||
| top.values().map { | ||
| escapeValue(renderValueForStdout(it, valueLimit, decimalFormat = decimalFormat).truncatedContent) |
There was a problem hiding this comment.
maybe create a new issue for exploring rendering nested frames as <details> like toStaticHtml? or at least mention this option in some kdoc :) Speaking of... small kdoc please? :))
|
@Jolanrensen please have a look when you have time. I checked default print output on a 7500 rows x 77 columns "real world data" output and from there made a bunch of changes. One important is always printing column types and on a separate line, which i think makes a lot of sense for String API ease of use / dataschema declarations. |
|
Wow awesome!
I agree, especially with large columnGroup/frameColumn types! Small concern about this approach though with I wonder how other libraries solve this. Maybe we could mark our types somehow too? Something like or Okay, my examples are quite ugly, but you get the idea |
Without index = true it's indeed a bit confusing
pandas simply doesn't render types in print, looks like they instead provide "info" akin to our "describe".
Maybe backticks are good option for us. Should we wrap always or only when index = false?
|
| ): String { | ||
| val sb = StringBuilder() | ||
| val table = prepareTable(rowsLimit, valueLimit, columnTypes, rowIndex) | ||
| val columnLengths = table.values.mapIndexed { col, vals -> |
There was a problem hiding this comment.
wait... so this is the... width... of each column in number of characters?
| rowIndex: Boolean = true, | ||
| ): String = renderToString(rowsLimit, valueLimit, borders, alignLeft, columnTypes, title, rowIndex) | ||
|
|
||
| public interface StringBorderRenderingStyle { |
There was a problem hiding this comment.
I think you could drop the "Rendering" part. "StringBorderStyle" is already clear enough (probably "BorderStyle" too if we think it doesn't clutter the rest of the library too much)
Oh the R brackets may also work :) I think I like them better (probably because I'm used to seeing types inside compared to: As for when we should wrap them, I think we should just always do it. We had May be a bit overboard for frameColumns, but it is still quite clear we're talking about types: |
|
btw, what about markdown? can we / should we also display the type on a new line? Does md even support mutliple-lines in headers? Edit:
|
|
I'm not so in favor of mandatory brackets :( As for newlines in markdown, i didn't think about |
It does provide a clearer picture, no? :) otherwise, we can always add a setting which turns it off. I liked them in the R table :) As for Markdown... hmm, I think we could still offer it. It's like a hybrid between ascii and html, like, it's readable, but also renderable. I think there's some value in that. But then we should probably keep it as flat and simple as possible, because, as you say, for more advanced cases, we can just turn to HTML. |

fixes #525
First, i added more tests on original renderToString. Then a little refactoring to extract common logic. +new function
Original rendering has some quirks that can be seen in test asserts. For now i just preserved it as is, but probably let's improve it as well - it will be more obvious with new tests