Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#890 - Cannot call .map {} on ColumnGroup #1007

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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 <[email protected]>
@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 :) )

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