Is there a way to apply for formatting option to a Dataframe column outside of the explicit description(options:) method?

I'm building up a data frame for the sole purpose of using that lovely textual grid output. I'm getting output without any issue, but I'm trying to sort out how I might apply a formatter to a specific column so that print(dataframeInstance) "just works" nicely. In my use case, I'm running a function, collecting its output - appending that into a frame, and then using TabularData to get a nice output in a unit test, so I can see the patterns within the output.

I found https://developer.apple.com/documentation/tabulardata/column/description(options:), but wasn't able to find any way to "pre-bind" that to a dataframe Column when I was creating it. (I have some double values that get a bit "excessive" in length due to the joys of floating point rounding)

Is there a way of setting a formatter on a column at creation time, or after (using a property) that could basically use the same pattern as that description method above?

Answered by Frameworks Engineer in 773350022

You could convert the Double values to strings yourself before putting them in the DataFrame. Or you could use map to convert them: dataFrame["values"] = dataFrame["values", Double.self].mapNonNil({ String(format: "%.2f", $0) }).eraseToAnyColumn()

Accepted Answer

You could convert the Double values to strings yourself before putting them in the DataFrame. Or you could use map to convert them: dataFrame["values"] = dataFrame["values", Double.self].mapNonNil({ String(format: "%.2f", $0) }).eraseToAnyColumn()

Is there a way to apply for formatting option to a Dataframe column outside of the explicit description(options:) method?
 
 
Q