@@ -11,7 +11,6 @@ import org.jetbrains.kotlinx.dataframe.DataColumn
11
11
import org.jetbrains.kotlinx.dataframe.DataFrame
12
12
import org.jetbrains.kotlinx.dataframe.DataRow
13
13
import org.jetbrains.kotlinx.dataframe.Predicate
14
- import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
15
14
import org.jetbrains.kotlinx.dataframe.columns.ColumnAccessor
16
15
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
17
16
import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
@@ -38,12 +37,11 @@ import org.jetbrains.kotlinx.dataframe.impl.columns.changePath
38
37
import org.jetbrains.kotlinx.dataframe.impl.columns.createColumnSet
39
38
import org.jetbrains.kotlinx.dataframe.impl.columns.getAt
40
39
import org.jetbrains.kotlinx.dataframe.impl.columns.getChildrenAt
41
- import org.jetbrains.kotlinx.dataframe.impl.columns.single
40
+ import org.jetbrains.kotlinx.dataframe.impl.columns.singleImpl
42
41
import org.jetbrains.kotlinx.dataframe.impl.columns.top
43
42
import org.jetbrains.kotlinx.dataframe.impl.columns.transform
44
43
import org.jetbrains.kotlinx.dataframe.impl.columns.transformSingle
45
44
import org.jetbrains.kotlinx.dataframe.impl.columns.tree.dfs
46
- import org.jetbrains.kotlinx.dataframe.io.read
47
45
import kotlin.reflect.KProperty
48
46
import kotlin.reflect.KType
49
47
import kotlin.reflect.typeOf
@@ -267,6 +265,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
267
265
*
268
266
* @param [condition\] The optional [ColumnFilter] condition that the column must adhere to.
269
267
* @return A [SingleColumn] containing the first column that adheres to the given [condition\].
268
+ * @throws [NoSuchElementException\] if no column adheres to the given [condition\].
270
269
* @see [last\]
271
270
*/
272
271
private interface CommonFirstDocs {
@@ -287,10 +286,11 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
287
286
*
288
287
* @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
289
288
* @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the first column that adheres to the given [condition].
289
+ * @throws [NoSuchElementException] if no column adheres to the given [condition].
290
290
* @see [last]
291
291
*/
292
292
public fun <C > ColumnSet<C>.first (condition : ColumnFilter <C > = { true }): SingleColumn <C > =
293
- transform { listOf (it.first(condition)) }.single ()
293
+ transform { listOf (it.first(condition)) }.singleImpl ()
294
294
295
295
/* *
296
296
* ## First
@@ -304,6 +304,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
304
304
*
305
305
* @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
306
306
* @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the first column that adheres to the given [condition].
307
+ * @throws [NoSuchElementException] if no column adheres to the given [condition].
307
308
* @see [last]
308
309
*/
309
310
public fun first (condition : ColumnFilter <* > = { true }): SingleColumn <* > =
@@ -321,6 +322,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
321
322
*
322
323
* @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
323
324
* @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the first column that adheres to the given [condition].
325
+ * @throws [NoSuchElementException] if no column adheres to the given [condition].
324
326
* @see [last]
325
327
*/
326
328
public fun ColumnGroupReference.first (condition : ColumnFilter <* > = { true }): SingleColumn <* > =
@@ -336,6 +338,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
336
338
*
337
339
* @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
338
340
* @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the first column that adheres to the given [condition].
341
+ * @throws [NoSuchElementException] if no column adheres to the given [condition].
339
342
* @see [last]
340
343
*/
341
344
public fun String.first (condition : ColumnFilter <* > = { true }): SingleColumn <* > =
@@ -351,9 +354,10 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
351
354
*
352
355
* @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
353
356
* @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the first column that adheres to the given [condition].
357
+ * @throws [NoSuchElementException] if no column adheres to the given [condition].
354
358
* @see [last]
355
359
*/
356
- public fun KProperty <* >.first (condition : ColumnFilter <* >): SingleColumn <* > =
360
+ public fun KProperty <* >.first (condition : ColumnFilter <* > = { true } ): SingleColumn <* > =
357
361
getColumnGroup(this ).first(condition)
358
362
359
363
@@ -367,6 +371,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
367
371
*
368
372
* @param [condition\] The optional [ColumnFilter] condition that the column must adhere to.
369
373
* @return A [SingleColumn] containing the last column that adheres to the given [condition\].
374
+ * @throws [NoSuchElementException\] if no column adheres to the given [condition\].
370
375
* @see [first\]
371
376
*/
372
377
private interface CommonLastDocs {
@@ -387,10 +392,11 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
387
392
*
388
393
* @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
389
394
* @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the last column that adheres to the given [condition].
395
+ * @throws [NoSuchElementException] if no column adheres to the given [condition].
390
396
* @see [first]
391
397
*/
392
398
public fun <C > ColumnSet<C>.last (condition : ColumnFilter <C > = { true }): SingleColumn <C > =
393
- transform { listOf (it.last(condition)) }.single ()
399
+ transform { listOf (it.last(condition)) }.singleImpl ()
394
400
395
401
/* *
396
402
* ## Last
@@ -404,6 +410,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
404
410
*
405
411
* @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
406
412
* @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the last column that adheres to the given [condition].
413
+ * @throws [NoSuchElementException] if no column adheres to the given [condition].
407
414
* @see [first]
408
415
*/
409
416
public fun last (condition : ColumnFilter <* > = { true }): SingleColumn <* > =
@@ -421,6 +428,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
421
428
*
422
429
* @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
423
430
* @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the last column that adheres to the given [condition].
431
+ * @throws [NoSuchElementException] if no column adheres to the given [condition].
424
432
* @see [first]
425
433
*/
426
434
public fun ColumnGroupReference.last (condition : ColumnFilter <* > = { true }): SingleColumn <* > =
@@ -436,6 +444,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
436
444
*
437
445
* @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
438
446
* @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the last column that adheres to the given [condition].
447
+ * @throws [NoSuchElementException] if no column adheres to the given [condition].
439
448
* @see [first]
440
449
*/
441
450
public fun String.last (condition : ColumnFilter <* > = { true }): SingleColumn <* > =
@@ -451,15 +460,119 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
451
460
*
452
461
* @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
453
462
* @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the last column that adheres to the given [condition].
463
+ * @throws [NoSuchElementException] if no column adheres to the given [condition].
454
464
* @see [first]
455
465
*/
456
- public fun KProperty <* >.last (condition : ColumnFilter <* >): SingleColumn <* > =
466
+ public fun KProperty <* >.last (condition : ColumnFilter <* > = { true } ): SingleColumn <* > =
457
467
getColumnGroup(this ).last(condition)
458
468
459
- public fun <C > ColumnSet<C>.single (condition : ColumnFilter <C >): SingleColumn <C > =
460
- transform { listOf (it.single(condition)) }.single()
461
469
462
- public fun SingleColumn<AnyRow>.col (index : Int ): SingleColumn <Any ?> = getChildrenAt(index).single()
470
+ /* *
471
+ * ## Single
472
+ * Returns the single column in this [ColumnSet] or [ColumnGroup] that adheres to the given [condition\].
473
+ *
474
+ * For example:
475
+ *
476
+ * {@includeArg [Examples]}
477
+ *
478
+ * @param [condition\] The optional [ColumnFilter] condition that the column must adhere to.
479
+ * @return A [SingleColumn] containing the single column that adheres to the given [condition\].
480
+ * @throws [NoSuchElementException\] if no column adheres to the given [condition\].
481
+ * @throws [IllegalArgumentException\] if more than one column adheres to the given [condition\].
482
+ */
483
+ private interface CommonSingleDocs {
484
+
485
+ /* * Examples key */
486
+ interface Examples
487
+ }
488
+
489
+ /* *
490
+ * ## Single
491
+ * Returns the single column in this [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] or [ColumnGroup][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup] that adheres to the given [condition].
492
+ *
493
+ * For example:
494
+ *
495
+ * `df.`[select][select]` { `[colsOf][colsOf]`<`[String][String]`>().`[single][single]` { it.`[name][ColumnReference.name]`().`[startsWith][String.startsWith]`("year") } }`
496
+ *
497
+ * `df.`[select][select]` { `[colsOf][colsOf]`<`[Int][Int]`>().`[single][single]`() }`
498
+ *
499
+ * @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
500
+ * @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the single column that adheres to the given [condition].
501
+ * @throws [NoSuchElementException] if no column adheres to the given [condition].
502
+ * @throws [IllegalArgumentException] if more than one column adheres to the given [condition].
503
+ */
504
+ public fun <C > ColumnSet<C>.single (condition : ColumnFilter <C > = { true }): SingleColumn <C > =
505
+ transform { listOf (it.single(condition)) }.singleImpl()
506
+
507
+ /* *
508
+ * ## Single
509
+ * Returns the single column in this [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] or [ColumnGroup][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup] that adheres to the given [condition].
510
+ *
511
+ * For example:
512
+ *
513
+ * `df.`[select][select]` { `[single][single]` { it.`[name][ColumnReference.name]`().`[startsWith][String.startsWith]`("year") } }`
514
+ *
515
+ * `df.`[select][select]` { `[single][single]`() }`
516
+ *
517
+ * @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
518
+ * @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the single column that adheres to the given [condition].
519
+ * @throws [NoSuchElementException] if no column adheres to the given [condition].
520
+ * @throws [IllegalArgumentException] if more than one column adheres to the given [condition].
521
+ */
522
+ public fun single (condition : ColumnFilter <* > = { true }): SingleColumn <* > =
523
+ all().single(condition)
524
+
525
+ /* *
526
+ * ## Single
527
+ * Returns the single column in this [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] or [ColumnGroup][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup] that adheres to the given [condition].
528
+ *
529
+ * For example:
530
+ *
531
+ * `df.`[select][select]` { myColumnGroup.`[single][single]` { it.`[name][ColumnReference.name]`().`[startsWith][String.startsWith]`("year") } }`
532
+ *
533
+ * `df.`[select][select]` { myColumnGroup.`[single][single]`() }`
534
+ *
535
+ * @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
536
+ * @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the single column that adheres to the given [condition].
537
+ * @throws [NoSuchElementException] if no column adheres to the given [condition].
538
+ * @throws [IllegalArgumentException] if more than one column adheres to the given [condition].
539
+ */
540
+ public fun ColumnGroupReference.single (condition : ColumnFilter <* > = { true }): SingleColumn <* > =
541
+ all().single(condition)
542
+
543
+ /* *
544
+ * ## Single
545
+ * Returns the single column in this [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] or [ColumnGroup][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup] that adheres to the given [condition].
546
+ *
547
+ * For example:
548
+ *
549
+ * `df.`[select][select]` { "myColumnGroup".`[single][single]` { it.`[name][ColumnReference.name]`().`[startsWith][String.startsWith]`("year") } }`
550
+ *
551
+ * @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
552
+ * @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the single column that adheres to the given [condition].
553
+ * @throws [NoSuchElementException] if no column adheres to the given [condition].
554
+ * @throws [IllegalArgumentException] if more than one column adheres to the given [condition].
555
+ */
556
+ public fun String.single (condition : ColumnFilter <* > = { true }): SingleColumn <* > =
557
+ getColumnGroup(this ).single(condition)
558
+
559
+ /* *
560
+ * ## Single
561
+ * Returns the single column in this [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] or [ColumnGroup][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup] that adheres to the given [condition].
562
+ *
563
+ * For example:
564
+ *
565
+ * `df.`[select][select]` { Type::myColumnGroup.`[single][single]` { it.`[name][ColumnReference.name]`().`[startsWith][String.startsWith]`("year") } }`
566
+ *
567
+ * @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
568
+ * @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the single column that adheres to the given [condition].
569
+ * @throws [NoSuchElementException] if no column adheres to the given [condition].
570
+ * @throws [IllegalArgumentException] if more than one column adheres to the given [condition].
571
+ */
572
+ public fun KProperty <* >.single (condition : ColumnFilter <* > = { true }): SingleColumn <* > =
573
+ getColumnGroup(this ).single(condition)
574
+
575
+ public fun SingleColumn<AnyRow>.col (index : Int ): SingleColumn <Any ?> = getChildrenAt(index).singleImpl()
463
576
464
577
public operator fun <C > ColumnSet<C>.get (index : Int ): SingleColumn <C > = getAt(index)
465
578
0 commit comments