Skip to content

Commit eaac104

Browse files
committed
Make getRows delegate to member function get so it's possible to override
1 parent 7795911 commit eaac104

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataFrame.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ public interface DataFrame<out T> :
102102
@RequiredByIntellijPlugin
103103
public operator fun get(index: Int): DataRow<T>
104104

105-
public operator fun get(indices: Iterable<Int>): DataFrame<T> = getRows(indices)
105+
public operator fun get(indices: Iterable<Int>): DataFrame<T> =
106+
columns().map { col -> col[indices] }.toDataFrame().cast()
106107

107-
public operator fun get(range: IntRange): DataFrame<T> = getRows(range)
108+
public operator fun get(range: IntRange): DataFrame<T> =
109+
if (range == indices()) this else columns().map { col -> col[range] }.toDataFrame().cast()
108110

109111
public operator fun get(first: IntRange, vararg ranges: IntRange): DataFrame<T> =
110112
getRows(headPlusArray(first, ranges).asSequence().flatMap { it.asSequence() }.asIterable())

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/DataFrameGet.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ public fun <T> DataFrame<T>.getColumns(vararg columns: String): List<AnyCol> = g
4545

4646
public fun <T> DataFrame<T>.getColumnIndex(col: AnyCol): Int = getColumnIndex(col.name())
4747

48-
public fun <T> DataFrame<T>.getRows(range: IntRange): DataFrame<T> =
49-
if (range == indices()) this else columns().map { col -> col[range] }.toDataFrame().cast()
48+
public fun <T> DataFrame<T>.getRows(range: IntRange): DataFrame<T> = get(range)
5049

51-
public fun <T> DataFrame<T>.getRows(indices: Iterable<Int>): DataFrame<T> =
52-
columns().map { col -> col[indices] }.toDataFrame().cast()
50+
public fun <T> DataFrame<T>.getRows(indices: Iterable<Int>): DataFrame<T> = get(indices)
5351

5452
public fun <T> DataFrame<T>.getOrNull(index: Int): DataRow<T>? = if (index < 0 || index >= nrow) null else get(index)
5553

0 commit comments

Comments
 (0)