`indices()` on `BaseColumn` is ambiguous for a `ColumnGroup`
メンテナーはふだん 1 日以内に返信
@zaleslaw がすでに取り組んでいます。
2026年9月8日 から。
評価
この issue はまだ評価されていません。
説明
indices() on BaseColumn is ambiguous for a ColumnGroup
indices() exists on both BaseColumn and DataFrame:
| Declaration | Location |
|---|---|
public fun AnyBaseCol.indices(): IntRange = 0 until size() |
core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataColumn.kt:325 |
public fun DataFrame<*>.indices(): IntRange = 0 until rowsCount() |
core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/indices.kt:38 |
ColumnGroup<T> derives from both (core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/columns/ColumnGroup.kt):
public interface ColumnGroup<out T> :
BaseColumn<DataRow<T>>,
DataFrame<T> {
Neither candidate is more specific for a column group, so calling indices() on one does not compile.
Reproducer
Put this file at
samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/IndicesAmbiguityRepro.kt:
package org.jetbrains.kotlinx.dataframe.samples.api
import org.jetbrains.kotlinx.dataframe.api.indices
import org.jetbrains.kotlinx.dataframe.indices
import org.junit.Test
class IndicesAmbiguityRepro : TestBase {
val df = peopleDf
@Test
fun repro() {
df.name.indices()
}
}
df.name is a ColumnGroup<Name> — peopleDf groups firstName and lastName into name.
Line 12 is df.name.indices(), column 17 is the indices token.
Run:
./gradlew :samples:compileTestKotlin
Output:
> Task :samples:compileTestKotlin FAILED
e: file:///.../samples/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/IndicesAmbiguityRepro.kt:12:17 Overload resolution ambiguity between candidates:
fun DataFrame<*>.indices(): IntRange
fun BaseColumn<*>.indices(): IntRange
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':samples:compileTestKotlin' (registered by plugin 'org.jetbrains.kotlin.jvm').
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.btapi.BuildToolsApiCompilationWork
> Compilation error. See log for more details
Do not check this from inside :core
The same call compiles in :core when the calling file sits in package
org.jetbrains.kotlinx.dataframe.api. There DataFrame.indices() comes from the same package
and loses to the explicit import org.jetbrains.kotlinx.dataframe.indices, so only one candidate
is considered and the ambiguity never appears. A probe in :core returns 0..2 for a
three-row column group and looks perfectly healthy. :samples is the module that reflects a
user's import set.
The property form is not affected
public val AnyCol.indices: IntRange (DataColumn.kt:317) is declared on AnyCol, which is
DataColumn<*>. ColumnGroup does not derive from DataColumn — that is deliberate, per its
own KDoc: "It derives not from DataColumn, but from BaseColumn to avoid API clashes between
DataFrame and DataColumn." So the property simply does not apply to a column group, and
there is nothing to be ambiguous about. Only the function form is broken.
Why it happens
The placement rule is written in the types themselves.
BaseColumn:
Column operations that doesn't clash by signature with
DataFrameoperations can be defined
forBaseColumn
DataColumn:
Column operations that have signature clash with
DataFrameAPI (filter,take,mapetc.)
are defined forDataColumnand not forBaseColumn.
indices() does clash with DataFrame.indices(), so by that rule it belongs on DataColumn,
next to filter/take/map. Putting it on BaseColumn looks like an oversight.
Suggested fix
Narrow the receiver of indices() from AnyBaseCol to AnyCol. The function and the indices
property then agree on the receiver, and a column group resolves to DataFrame.indices() — which
returns the same range anyway, because ColumnGroupImpl.size() is rowsCount()
(core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/columns/ColumnGroupImpl.kt):
override fun size() = rowsCount()
Impact:
ValueColumnandFrameColumnareDataColumn, so they are unaffected.- The only in-repo use of
indiceson aColumnGroupreceiver is
core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/reverse.kt:91:
It uses the property. There are exactly twopublic fun <T> ColumnGroup<T>.reverse(): ColumnGroup<T> = get(indices.reversed())indicesproperties —AnyCol.indicesand the
internal val AnyFrame.indices(DataFrame.kt:182) — and the first does not apply to a
column group, so this line already goes through theDataFrameside. No internal caller
depends on the function form for column groups. - Narrowing the receiver of a public extension is source-breaking for any caller holding a
BaseColumn, so this needs anapiDumpand probably a deprecation cycle rather than a
straight edit.
Current behaviour, for reference
Measured on a three-element column, and on a column group and a frame column built from a
three-row dataframe:
| Call | Result |
|---|---|
col.indices |
0..2 |
col.indices() |
0..2 |
base.indices(), where val base: AnyBaseCol = col |
0..2 |
group.indices() (from :core, where it compiles) |
0..2 |
group.size() / group.rowsCount() |
3 / 3 |
frameCol.indices / frameCol.indices() |
0..2 |
frameCol.size() |
3 |
IndicesTests (core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/indices.kt, region
on a column) pins this down. The column-group case goes through a receiver explicitly typed as
AnyBaseCol, because that is the only way to call it today without hitting the ambiguity.
Tests are here: https://github.com/Kotlin/dataframe/pull/2068
- 主要言語
- Kotlin
- スター
- 1.1k
- フォーク
- 87
- 平均マージ
- 2日 21時間
- マージ済み PR(30日)
- 40
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Kotlin/dataframe のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
API
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
Kotlin/dataframe#2202 · コメント 3 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Kotlin/dataframe#2195 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
AX
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
Add minimal KDocs for `print` APIs対応中かも @zaleslaw が 5 日前に担当しました。 オープンKDocs
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
Kotlin/dataframe の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
IacobIonut01/ReFra#1388 ·
メンテナーはふだん 17 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
slackhq/slack-lints#525 ·
-
backend prio:low
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
digitalfabrik/entitlementcard#3262 ·
メンテナーはふだん 2 日以内に返信
-
Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
keiyoushi/extensions-source#20893 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信