Skip to content

Conversation

@ysknsid25
Copy link

Fix issue #890

If you want to use DataFrame<T>.map(), you can usually just call it with the default arguments. If you have something else you want to transform, I don't mind returning the result of passing it to you.

before

image

after

image

Fix Overload

Signed-off-by: ysknsid25 <kengo071225@gmail.com>
@Jolanrensen
Copy link
Collaborator

Thank you very much!

It does, however, seem that your fix breaks the notation:

df.map { ... }

as seen in the test here: https://github.com/ysknsid25/dataframe/blob/b67c665cb10375ac13f2dd9bca8aa838af522082/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Modify.kt#L1130

I think it may be easier to just provide another map function but defined on ColumnGroup instead of DataFrame. I suspect this will work, because the compiler always chooses the function that matches the provided type the closest. Could you try?

@ysknsid25
Copy link
Author

I defined the following in map.kt, but it did not resolve the ambiguous overload 🫠

// region ColumnGroup

public fun <T, R> ColumnGroup<T>.map(transform: (AnyCol) -> R): List<R> = columns().map { transform(it) }

// endregion

image

@Jolanrensen
Copy link
Collaborator

I see :( that's a shame.

Then the only solution may be to add

public fun <R> map(transform: RowExpression<T, R>): List<R> = asDataFrame().map(transform)

directly inside the ColumnGroup interface. Member functions do always have priority over extension functions, so it would probably work fine. (just need to check if it doesn't break anything else :) )

@ysknsid25 ysknsid25 closed this Mar 22, 2025
@Jolanrensen
Copy link
Collaborator

I see :( that's a shame.

Then the only solution may be to add

public fun <R> map(transform: RowExpression<T, R>): List<R> = asDataFrame().map(transform)

directly inside the ColumnGroup interface. Member functions do always have priority over extension functions, so it would probably work fine. (just need to check if it doesn't break anything else :) )

Another would be to use @HidesMember from https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/src/kotlin/internal/Annotations.kt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants