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

"" + columnRef becomes String #750

Closed
sorokod opened this issue Jun 23, 2024 · 3 comments
Closed

"" + columnRef becomes String #750

sorokod opened this issue Jun 23, 2024 · 3 comments
Labels
wontfix This will not be worked on
Milestone

Comments

@sorokod
Copy link

sorokod commented Jun 23, 2024

Sample code (version 0.12.0):

    val df1 = dataFrameOf("name", "age")(
        "Alice", 15,
        "Bob", 20,
        "Charlie", 100
    )

    val name  by column<String>()
    val name_age by column<String>()

    df1.add(name_age) { name + "!!!" }.also { println(it) }
    df1.add(name_age) { "!!!" + name  }.also { println(it) }

The first println (name + "!!!") produces:

      name age   name_age
 0   Alice  15   Alice!!!
 1     Bob  20     Bob!!!
 2 Charlie 100 Charlie!!!

The second println ( "!!!" + name) produces:

      name age                                 name_age
 0   Alice  15 !!!org.jetbrains.kotlinx.dataframe.im...
 1     Bob  20 !!!org.jetbrains.kotlinx.dataframe.im...
 2 Charlie 100 !!!org.jetbrains.kotlinx.dataframe.im...

The root cause is that In the two example + resolves to different functions. A foot gun that should be fixed.

@Jolanrensen
Copy link
Collaborator

It should indeed be fixed but unfortunately we can't. It's a language limitation.

Have you tried making a function like operator fun String.plus(something)?
image
Since String already has a function plus, an extension function overload will never be called by default.

@Jolanrensen Jolanrensen added bug Something isn't working wontfix This will not be worked on labels Jun 24, 2024
@sorokod
Copy link
Author

sorokod commented Jun 24, 2024

I would consider deprecating, and ultimately removing:

public operator fun ColumnReference<String>.plus.

@Jolanrensen
Copy link
Collaborator

Might indeed be a good idea to add ColumReference<String>.append() and .prepend() or something similar and through deprecations steer users to those :)
We still cannot prevent "" + anything from becoming a String though

@Jolanrensen Jolanrensen changed the title tyepe of a cell value in a new column depends on the order of calculation "" + columnRef becomes String Jun 25, 2024
@zaleslaw zaleslaw removed the bug Something isn't working label Jul 19, 2024
@zaleslaw zaleslaw added this to the 0.14.0 milestone Jul 19, 2024
@zaleslaw zaleslaw closed this as not planned Won't fix, can't repro, duplicate, stale Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants