Dataframe 0.14 Help

Use external Data Schemas in Jupyter

Sometimes it is convenient to extract reusable code from Jupyter Notebook into the Kotlin JVM library. Schema interfaces should also be extracted if this code uses Custom Data Schemas.

In order to enable support them in Jupyter, you should register them in library integration class with useSchema function:

@DataSchema interface Person { val name: String val age: Int } fun DataFrame<Person>.countAdults() = count { it[Person::age] > 18 } @JupyterLibrary internal class Integration : JupyterIntegration() { override fun Builder.onLoaded() { onLoaded { useSchema<Person>() } } }

After loading this library into Jupyter notebook, schema interfaces for all DataFrame variables that match Person schema will derive from Person

val df = dataFrameOf("name", "age")( "Alice", 15, "Bob", 20, )

Now df is assignable to DataFrame<Person> and countAdults is available:

df.countAdults()
Last modified: 27 September 2024