So this causes an exception, as expected:
dataFrameOf("a" to columnOf(123, 322), "b" to columnOf(1.0, null)).convert { a and b }.to<Double>()
Method threw 'org.jetbrains.kotlinx.dataframe.exceptions.CellConversionException' exception.
I think this exception is the reason why two overloads for each operation were introduced:
public fun <T> Convert<T, Any>.toDouble(): DataFrame<T> = to<Double>()
public fun <T> Convert<T, Any?>.toDouble(): DataFrame<T> = to<Double?>()
But i want to argue it's actually redundant, public fun <T> Convert<T, Any?>.toDouble(): DataFrame<T> = to<Double?>() is enough:
If mixed nullability columns are selected, to<Double?>() is resolved
dataFrameOf("a" to columnOf(123, 322), "b" to columnOf(1.0, null)).convert { a and b }.toDouble()
And its result is accurate, a still has not-null Double type, just as originally it was Int.
So in terms of type accuracy public fun <T> Convert<T, Any>.toDouble(): DataFrame<T> = to<Double>() is not needed.
Now let's return to the exception. If we deceive the compiler and resolve wrong overload, that normally wouldn't be resolved, then we get exception (that we might expect, since all our columns are Int! (not really))
dataFrameOf("a" to columnOf(123, 322), "b" to columnOf(1, null)).convert { (a and b).cast<Int>() }.toDouble()
Let's check other column selectors. all() -> ColumnSelector<Any?>, so again "nullable" overload is resolved.
dataFrameOf("a" to columnOf(123, 322), "b" to columnOf(1, null)).convert { all() }.toDouble()
Looks like we can remove ~27 overloads from convert.kt and everything will work same as before
So this causes an exception, as expected:
Method threw 'org.jetbrains.kotlinx.dataframe.exceptions.CellConversionException' exception.
I think this exception is the reason why two overloads for each operation were introduced:
But i want to argue it's actually redundant,
public fun <T> Convert<T, Any?>.toDouble(): DataFrame<T> = to<Double?>()is enough:If mixed nullability columns are selected,
to<Double?>()is resolvedAnd its result is accurate, a still has not-null Double type, just as originally it was Int.
So in terms of type accuracy
public fun <T> Convert<T, Any>.toDouble(): DataFrame<T> = to<Double>()is not needed.Now let's return to the exception. If we deceive the compiler and resolve wrong overload, that normally wouldn't be resolved, then we get exception (that we might expect, since all our columns are Int! (not really))
Let's check other column selectors. all() -> ColumnSelector<Any?>, so again "nullable" overload is resolved.
Looks like we can remove ~27 overloads from convert.kt and everything will work same as before