@@ -4,6 +4,7 @@ import com.beust.klaxon.JsonArray
4
4
import com.beust.klaxon.JsonObject
5
5
import com.beust.klaxon.Parser
6
6
import io.kotest.assertions.throwables.shouldNotThrow
7
+ import io.kotest.matchers.collections.shouldContain
7
8
import io.kotest.matchers.comparables.shouldBeGreaterThan
8
9
import io.kotest.matchers.comparables.shouldBeLessThan
9
10
import io.kotest.matchers.shouldBe
@@ -212,6 +213,156 @@ class RenderingTests : JupyterReplTestCase() {
212
213
}
213
214
}
214
215
216
+ @Test
217
+ fun `json metadata contains schema metadata` () {
218
+ val json = executeScriptAndParseDataframeResult(
219
+ """
220
+ val col1 by columnOf("a", "b", "c")
221
+ val col2 by columnOf(1, 2, 3)
222
+ val col3 by columnOf("Foo", "Bar", null)
223
+ val df2 = dataFrameOf(Pair("header", listOf("A", "B", "C")))
224
+ val col4 by columnOf(df2, df2, df2)
225
+ var df = dataFrameOf(col1, col2, col3, col4)
226
+ df.group(col1, col2).into("group")
227
+ """ .trimIndent()
228
+ )
229
+ val jsonOutput = json.toJsonString(prettyPrint = true )
230
+ val expectedOutput = """
231
+ {
232
+ "${' $' } version": "2.1.0",
233
+ "metadata": {
234
+ "columns": ["group", "col3", "col4"],
235
+ "types": [{
236
+ "kind": "ColumnGroup"
237
+ }, {
238
+ "kind": "ValueColumn",
239
+ "type": "kotlin.String?"
240
+ }, {
241
+ "kind": "FrameColumn"
242
+ }],
243
+ "nrow": 3,
244
+ "ncol": 3
245
+ },
246
+ "kotlin_dataframe": [{
247
+ "group": {
248
+ "data": {
249
+ "col1": "a",
250
+ "col2": 1
251
+ },
252
+ "metadata": {
253
+ "kind": "ColumnGroup",
254
+ "columns": ["col1", "col2"],
255
+ "types": [{
256
+ "kind": "ValueColumn",
257
+ "type": "kotlin.String"
258
+ }, {
259
+ "kind": "ValueColumn",
260
+ "type": "kotlin.Int"
261
+ }]
262
+ }
263
+ },
264
+ "col3": "Foo",
265
+ "col4": {
266
+ "data": [{
267
+ "header": "A"
268
+ }, {
269
+ "header": "B"
270
+ }, {
271
+ "header": "C"
272
+ }],
273
+ "metadata": {
274
+ "kind": "FrameColumn",
275
+ "columns": ["header"],
276
+ "types": [{
277
+ "kind": "ValueColumn",
278
+ "type": "kotlin.String"
279
+ }],
280
+ "ncol": 1,
281
+ "nrow": 3
282
+ }
283
+ }
284
+ }, {
285
+ "group": {
286
+ "data": {
287
+ "col1": "b",
288
+ "col2": 2
289
+ },
290
+ "metadata": {
291
+ "kind": "ColumnGroup",
292
+ "columns": ["col1", "col2"],
293
+ "types": [{
294
+ "kind": "ValueColumn",
295
+ "type": "kotlin.String"
296
+ }, {
297
+ "kind": "ValueColumn",
298
+ "type": "kotlin.Int"
299
+ }]
300
+ }
301
+ },
302
+ "col3": "Bar",
303
+ "col4": {
304
+ "data": [{
305
+ "header": "A"
306
+ }, {
307
+ "header": "B"
308
+ }, {
309
+ "header": "C"
310
+ }],
311
+ "metadata": {
312
+ "kind": "FrameColumn",
313
+ "columns": ["header"],
314
+ "types": [{
315
+ "kind": "ValueColumn",
316
+ "type": "kotlin.String"
317
+ }],
318
+ "ncol": 1,
319
+ "nrow": 3
320
+ }
321
+ }
322
+ }, {
323
+ "group": {
324
+ "data": {
325
+ "col1": "c",
326
+ "col2": 3
327
+ },
328
+ "metadata": {
329
+ "kind": "ColumnGroup",
330
+ "columns": ["col1", "col2"],
331
+ "types": [{
332
+ "kind": "ValueColumn",
333
+ "type": "kotlin.String"
334
+ }, {
335
+ "kind": "ValueColumn",
336
+ "type": "kotlin.Int"
337
+ }]
338
+ }
339
+ },
340
+ "col3": null,
341
+ "col4": {
342
+ "data": [{
343
+ "header": "A"
344
+ }, {
345
+ "header": "B"
346
+ }, {
347
+ "header": "C"
348
+ }],
349
+ "metadata": {
350
+ "kind": "FrameColumn",
351
+ "columns": ["header"],
352
+ "types": [{
353
+ "kind": "ValueColumn",
354
+ "type": "kotlin.String"
355
+ }],
356
+ "ncol": 1,
357
+ "nrow": 3
358
+ }
359
+ }
360
+ }]
361
+ }
362
+ """ .trimIndent()
363
+ jsonOutput shouldBe expectedOutput
364
+ }
365
+
215
366
@Test
216
367
fun `test kotlin dataframe conversion groupby` () {
217
368
val json = executeScriptAndParseDataframeResult(
0 commit comments