Skip to content

Commit c47f32c

Browse files
committed
rangeTo
1 parent bdf3ba3 commit c47f32c

File tree

4 files changed

+248
-92
lines changed

4 files changed

+248
-92
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/ColumnsSelectionDsl.kt

Lines changed: 169 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -300,32 +300,14 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
300300
*
301301
* `df.`[select][select]` { `[first][first]` { it.`[name][ColumnReference.name]`().`[startsWith][String.startsWith]`("year") } }`
302302
*
303-
* `df.`[select][select]` { `[first][first]`() }`
304-
*
305-
* @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
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].
308-
* @see [last]
309-
*/
310-
public fun first(condition: ColumnFilter<*> = { true }): SingleColumn<*> =
311-
all().first(condition)
312-
313-
/**
314-
* ## First
315-
* Returns the first column in this [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] or [ColumnGroup][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup] that adheres to the given [condition].
316-
*
317-
* For example:
318-
*
319-
* `df.`[select][select]` { myColumnGroup.`[first][first]` { it.`[name][ColumnReference.name]`().`[startsWith][String.startsWith]`("year") } }`
320-
*
321303
* `df.`[select][select]` { myColumnGroup.`[first][first]`() }`
322304
*
323305
* @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
324306
* @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the first column that adheres to the given [condition].
325307
* @throws [NoSuchElementException] if no column adheres to the given [condition].
326308
* @see [last]
327309
*/
328-
public fun ColumnGroupReference.first(condition: ColumnFilter<*> = { true }): SingleColumn<*> =
310+
public fun SingleColumn<AnyRow>.first(condition: ColumnFilter<*> = { true }): SingleColumn<*> =
329311
all().first(condition)
330312

331313
/**
@@ -406,32 +388,14 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
406388
*
407389
* `df.`[select][select]` { `[last][last]` { it.`[name][ColumnReference.name]`().`[startsWith][String.startsWith]`("year") } }`
408390
*
409-
* `df.`[select][select]` { `[first][last]`() }`
410-
*
411-
* @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
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].
414-
* @see [first]
415-
*/
416-
public fun last(condition: ColumnFilter<*> = { true }): SingleColumn<*> =
417-
all().last(condition)
418-
419-
/**
420-
* ## Last
421-
* Returns the last column in this [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] or [ColumnGroup][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup] that adheres to the given [condition].
422-
*
423-
* For example:
424-
*
425-
* `df.`[select][select]` { myColumnGroup.`[last][last]` { it.`[name][ColumnReference.name]`().`[startsWith][String.startsWith]`("year") } }`
426-
*
427391
* `df.`[select][select]` { myColumnGroup.`[last][last]`() }`
428392
*
429393
* @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
430394
* @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the last column that adheres to the given [condition].
431395
* @throws [NoSuchElementException] if no column adheres to the given [condition].
432396
* @see [first]
433397
*/
434-
public fun ColumnGroupReference.last(condition: ColumnFilter<*> = { true }): SingleColumn<*> =
398+
public fun SingleColumn<AnyRow>.last(condition: ColumnFilter<*> = { true }): SingleColumn<*> =
435399
all().last(condition)
436400

437401
/**
@@ -512,32 +476,14 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
512476
*
513477
* `df.`[select][select]` { `[single][single]` { it.`[name][ColumnReference.name]`().`[startsWith][String.startsWith]`("year") } }`
514478
*
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-
*
533479
* `df.`[select][select]` { myColumnGroup.`[single][single]`() }`
534480
*
535481
* @param [condition] The optional [ColumnFilter][org.jetbrains.kotlinx.dataframe.ColumnFilter] condition that the column must adhere to.
536482
* @return A [SingleColumn][org.jetbrains.kotlinx.dataframe.columns.SingleColumn] containing the single column that adheres to the given [condition].
537483
* @throws [NoSuchElementException] if no column adheres to the given [condition].
538484
* @throws [IllegalArgumentException] if more than one column adheres to the given [condition].
539485
*/
540-
public fun ColumnGroupReference.single(condition: ColumnFilter<*> = { true }): SingleColumn<*> =
486+
public fun SingleColumn<AnyRow>.single(condition: ColumnFilter<*> = { true }): SingleColumn<*> =
541487
all().single(condition)
542488

543489
/**
@@ -572,18 +518,184 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
572518
public fun KProperty<*>.single(condition: ColumnFilter<*> = { true }): SingleColumn<*> =
573519
getColumnGroup(this).single(condition)
574520

521+
/** TODO */
575522
public fun SingleColumn<AnyRow>.col(index: Int): SingleColumn<Any?> = getChildrenAt(index).singleImpl()
576523

524+
/** TODO */
577525
public operator fun <C> ColumnSet<C>.get(index: Int): SingleColumn<C> = getAt(index)
578526

527+
/** TODO */
579528
public fun ColumnsContainer<*>.group(name: String): ColumnGroupReference = name.toColumnOf()
580529

530+
/**
531+
* ## Subset of Columns
532+
* Returns a [ColumnSet] containing all columns from [this\] to [endInclusive\].
533+
*
534+
* For example:
535+
*
536+
* `df.`[select][DataFrame.select]` { `{@includeArg [Example]}` }`
537+
*
538+
* @param [endInclusive\] The last column in the subset.
539+
* @receiver The first column in the subset.
540+
* @return A [ColumnSet] containing all columns from [this\] to [endInclusive\].
541+
* @throws [IllegalArgumentException\] if the columns have different parents.
542+
*/
543+
private interface CommonSubsetOfColumnsDocs {
544+
545+
/** Examples key */
546+
interface Example
547+
}
548+
549+
/**
550+
* ## Subset of Columns
551+
* Returns a [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
552+
*
553+
* For example:
554+
*
555+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { `"fromColumn".."toColumn"` }`
556+
*
557+
* @param [endInclusive] The last column in the subset.
558+
* @receiver The first column in the subset.
559+
* @return A [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
560+
* @throws [IllegalArgumentException] if the columns have different parents.
561+
*
562+
*/
581563
public operator fun String.rangeTo(endInclusive: String): ColumnSet<*> =
582564
toColumnAccessor().rangeTo(endInclusive.toColumnAccessor())
583565

566+
/**
567+
* ## Subset of Columns
568+
* Returns a [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
569+
*
570+
* For example:
571+
*
572+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { `"fromColumn"..Type::toColumn` }`
573+
*
574+
* @param [endInclusive] The last column in the subset.
575+
* @receiver The first column in the subset.
576+
* @return A [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
577+
* @throws [IllegalArgumentException] if the columns have different parents.
578+
*
579+
*/
580+
public operator fun String.rangeTo(endInclusive: KProperty<*>): ColumnSet<*> =
581+
toColumnAccessor().rangeTo(endInclusive.toColumnAccessor())
582+
583+
/**
584+
* ## Subset of Columns
585+
* Returns a [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
586+
*
587+
* For example:
588+
*
589+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { `"fromColumn"..toColumn` }`
590+
*
591+
* @param [endInclusive] The last column in the subset.
592+
* @receiver The first column in the subset.
593+
* @return A [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
594+
* @throws [IllegalArgumentException] if the columns have different parents.
595+
*
596+
*/
597+
public operator fun String.rangeTo(endInclusive: AnyColumnReference): ColumnSet<*> =
598+
toColumnAccessor().rangeTo(endInclusive)
599+
600+
/**
601+
* ## Subset of Columns
602+
* Returns a [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
603+
*
604+
* For example:
605+
*
606+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { `Type::fromColumn.."toColumn"` }`
607+
*
608+
* @param [endInclusive] The last column in the subset.
609+
* @receiver The first column in the subset.
610+
* @return A [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
611+
* @throws [IllegalArgumentException] if the columns have different parents.
612+
*
613+
*/
614+
public operator fun KProperty<*>.rangeTo(endInclusive: String): ColumnSet<*> =
615+
toColumnAccessor().rangeTo(endInclusive.toColumnAccessor())
616+
617+
/**
618+
* ## Subset of Columns
619+
* Returns a [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
620+
*
621+
* For example:
622+
*
623+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { `Type::fromColumn..Type::toColumn` }`
624+
*
625+
* @param [endInclusive] The last column in the subset.
626+
* @receiver The first column in the subset.
627+
* @return A [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
628+
* @throws [IllegalArgumentException] if the columns have different parents.
629+
*
630+
*/
584631
public operator fun KProperty<*>.rangeTo(endInclusive: KProperty<*>): ColumnSet<*> =
585632
toColumnAccessor().rangeTo(endInclusive.toColumnAccessor())
586633

634+
/**
635+
* ## Subset of Columns
636+
* Returns a [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
637+
*
638+
* For example:
639+
*
640+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { `Type::fromColumn..toColumn` }`
641+
*
642+
* @param [endInclusive] The last column in the subset.
643+
* @receiver The first column in the subset.
644+
* @return A [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
645+
* @throws [IllegalArgumentException] if the columns have different parents.
646+
*
647+
*/
648+
public operator fun KProperty<*>.rangeTo(endInclusive: AnyColumnReference): ColumnSet<*> =
649+
toColumnAccessor().rangeTo(endInclusive)
650+
651+
/**
652+
* ## Subset of Columns
653+
* Returns a [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
654+
*
655+
* For example:
656+
*
657+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { `fromColumn.."toColumn"` }`
658+
*
659+
* @param [endInclusive] The last column in the subset.
660+
* @receiver The first column in the subset.
661+
* @return A [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
662+
* @throws [IllegalArgumentException] if the columns have different parents.
663+
*
664+
*/
665+
public operator fun AnyColumnReference.rangeTo(endInclusive: String): ColumnSet<*> =
666+
rangeTo(endInclusive.toColumnAccessor())
667+
668+
/**
669+
* ## Subset of Columns
670+
* Returns a [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
671+
*
672+
* For example:
673+
*
674+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { `fromColumn..Type::toColumn` }`
675+
*
676+
* @param [endInclusive] The last column in the subset.
677+
* @receiver The first column in the subset.
678+
* @return A [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
679+
* @throws [IllegalArgumentException] if the columns have different parents.
680+
*
681+
*/
682+
public operator fun AnyColumnReference.rangeTo(endInclusive: KProperty<*>): ColumnSet<*> =
683+
rangeTo(endInclusive.toColumnAccessor())
684+
685+
/**
686+
* ## Subset of Columns
687+
* Returns a [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
688+
*
689+
* For example:
690+
*
691+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { `fromColumn..toColumn` }`
692+
*
693+
* @param [endInclusive] The last column in the subset.
694+
* @receiver The first column in the subset.
695+
* @return A [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns from [this] to [endInclusive].
696+
* @throws [IllegalArgumentException] if the columns have different parents.
697+
*
698+
*/
587699
public operator fun AnyColumnReference.rangeTo(endInclusive: AnyColumnReference): ColumnSet<*> =
588700
object : ColumnSet<Any?> {
589701
override fun resolve(context: ColumnResolutionContext): List<ColumnWithPath<Any?>> {

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/ColumnsSelectionDsl.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,4 @@ class ColumnsSelectionDslTests : TestBase() {
110110
}
111111
} shouldBe df.select { name.firstName }
112112
}
113-
114113
}

0 commit comments

Comments
 (0)