Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with new types of data. #184

Open
AndreiKingsley opened this issue May 6, 2023 · 1 comment
Open

Working with new types of data. #184

AndreiKingsley opened this issue May 6, 2023 · 1 comment
Milestone

Comments

@AndreiKingsley
Copy link
Contributor

Suppose we use a non-typical data type for plotting, for example our own data class.

public data class A(val a: Int)
public fun main() {
    (letsPlot {
    } + geomPoint {
        x = listOf(A(1), A(2))
        y = listOf(1, 2)
        color = listOf(A(1), A(2))
    }).also {
        ggsave(it, "plot.png")
    }
}

When trying to create a plot with this type of data with png rendering everything works as we assume - data of this type are casted to String.

image

However, when we try to save to html or use notebook rendering, we get an exception:

public data class A(val a: Int)
public fun main() {
    println(A(5))
    (letsPlot {
    } + geomPoint {
        x = listOf(A(1), A(2))
        y = listOf(1, 2)
        color = listOf(A(1), A(2))
    }).also {
        ggsave(it, "plot.html")
    }
}
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.IllegalArgumentException: Can't serialize object A(a=1)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$1.invoke(JsObjectSupport.kt:49)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$1.invoke(JsObjectSupport.kt:40)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$handleList$1.invoke(JsObjectSupport.kt:20)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$handleList$1.invoke(JsObjectSupport.kt:15)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$1.invoke(JsObjectSupport.kt:47)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$1.invoke(JsObjectSupport.kt:40)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$handleMap$1.invoke(JsObjectSupport.kt:35)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$handleMap$1.invoke(JsObjectSupport.kt:25)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$1.invoke(JsObjectSupport.kt:48)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$1.invoke(JsObjectSupport.kt:40)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$handleMap$1.invoke(JsObjectSupport.kt:35)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$handleMap$1.invoke(JsObjectSupport.kt:25)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$1.invoke(JsObjectSupport.kt:48)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$1.invoke(JsObjectSupport.kt:40)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$handleList$1.invoke(JsObjectSupport.kt:20)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$handleList$1.invoke(JsObjectSupport.kt:15)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$1.invoke(JsObjectSupport.kt:47)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$1.invoke(JsObjectSupport.kt:40)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$handleMap$1.invoke(JsObjectSupport.kt:35)
	at jetbrains.datalore.base.jsObject.JsObjectSupport$mapToJsObjectInitializer$handleMap$1.invoke(JsObjectSupport.kt:25)
	at jetbrains.datalore.base.jsObject.JsObjectSupport.mapToJsObjectInitializer(JsObjectSupport.kt:53)
	at jetbrains.datalore.plot.PlotHtmlHelper.getStaticDisplayHtmlForRawSpec(PlotHtmlHelper.kt:123)
	at jetbrains.datalore.plot.PlotHtmlExport.buildHtmlFromRawSpecs(PlotHtmlExport.kt:30)
	at jetbrains.datalore.plot.PlotHtmlExport.buildHtmlFromRawSpecs$default(PlotHtmlExport.kt:22)
	at org.jetbrains.letsPlot.export.GgsaveKt.ggsave(ggsave.kt:77)
	at org.jetbrains.letsPlot.export.GgsaveKt.ggsave$default(ggsave.kt:44)
	at org.jetbrains.kotlinx.kandy.letsplot.MainKt.main(main.kt:16)
	at org.jetbrains.kotlinx.kandy.letsplot.MainKt.main(main.kt)

Indeed, the new type is not among the recognizable. The question is: why? I believe that the behavior with "png" should be repeated - just add toString() for unknown types.

@AndreiKingsley
Copy link
Contributor Author

Perhaps we should do this at the stage of transforming into a spec?

@alshan alshan added this to the 2023Q2 milestone May 11, 2023
@alshan alshan modified the milestones: 2023Q2, 2023Q3 Jun 28, 2023
@alshan alshan modified the milestones: 2023Q3, 2023Q4 Sep 29, 2023
@alshan alshan modified the milestones: 2023Q4, 2024Q1 Jan 2, 2024
@alshan alshan modified the milestones: 2024Q1, 2024Q2 Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants