-
Notifications
You must be signed in to change notification settings - Fork 82
Clarify that schema of property with DataFrame<T>? type is not a FrameColumn
#1925
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -193,7 +193,14 @@ internal fun AnyFrame.convertToImpl( | |
|
|
||
| when (targetSchema.kind) { | ||
| ColumnKind.Value -> | ||
| convertedColumn ?: originalColumn.convertTo(to) | ||
| when { | ||
| convertedColumn != null -> convertedColumn | ||
|
|
||
| originalColumn.kind == ColumnKind.Frame && to.jvmErasure == DataFrame::class -> | ||
| originalColumn | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you return
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Plus, if it does change the kind, this might enable converting
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If originalColumn has no nulls in runtime then creating ValueColumn is a violation and our checks fail
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So isn't this step then gonna break regardless? It converts FrameColumn -> ValueColumn
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Approach that i chose now is keeping runtime column "narrower" than compile time - it's usually a valid approach. So, even if target type is
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think logic like that will only complicate things more... Can we try to keep the rules the same everywhere?
This will make it much easier for us and to explain to users. So if the target type is
This will then also work correctly, right? because
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see now... that's indeed a problem. In that case
I suppose from the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this matches my understanding of the situation.
Yeah, this should be resolved. |
||
|
|
||
| else -> originalColumn.convertTo(to) | ||
| } | ||
|
|
||
| ColumnKind.Group -> { | ||
| val column = when { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,6 +184,21 @@ class ConvertToTests { | |
| @DataSchema | ||
| data class DataSchemaWithAnyFrame(val dfs: AnyFrame?) | ||
|
|
||
| private fun locationsFrame(): DataFrame<Location?> = | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does a
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we prohibit such types? Or explicitly allow them (changing "name" and "gps" to nullable versions and fill them with nulls, like in our json reader)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, that's indeed exactly what happens, I see.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, the compiler plugin will come up with a new type. But it might be worth to define this behavior as a rule (in docs, tests, etc).
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, but as a different issue |
||
| listOf( | ||
| Location("Home", Gps(0.0, 0.0)), | ||
| Location("Away", null), | ||
| null, | ||
| ).toDataFrame() | ||
| .alsoDebug("locations:") | ||
|
|
||
| private fun gpsFrame(): DataFrame<Gps?> = | ||
| listOf( | ||
| Gps(0.0, 0.0), | ||
| null, | ||
| ).toDataFrame() | ||
| .alsoDebug("gps:") | ||
|
|
||
| @Test | ||
| fun test() { | ||
| val df1 = dataFrameOf("a")(1, 2, 3) | ||
|
|
@@ -202,67 +217,70 @@ class ConvertToTests { | |
| } | ||
|
|
||
| @Test | ||
| fun `convert df with AnyFrame to itself`() { | ||
| val locationsList = listOf( | ||
| Location("Home", Gps(0.0, 0.0)), | ||
| Location("Away", null), | ||
| null, | ||
| ) | ||
| val locations = locationsList | ||
| .toDataFrame() | ||
| .alsoDebug("locations:") | ||
| fun `convert df with AnyFrame containing locations to itself`() { | ||
| val locations = locationsFrame() | ||
|
|
||
| val gpsList = listOf( | ||
| Gps(0.0, 0.0), | ||
| null, | ||
| ) | ||
| val gps = gpsList | ||
| listOf(DataSchemaWithAnyFrame(locations)) | ||
| .toDataFrame() | ||
| .alsoDebug("gps:") | ||
|
|
||
| val df1 = listOf( | ||
| DataSchemaWithAnyFrame(locations), | ||
| ).toDataFrame() | ||
| .alsoDebug("df1:") | ||
| .convertTo<DataSchemaWithAnyFrame>() | ||
| } | ||
|
|
||
| df1.convertTo<DataSchemaWithAnyFrame>() | ||
| @Test | ||
| fun `convert df with AnyFrame containing gps to itself`() { | ||
| val gps = gpsFrame() | ||
|
|
||
| val df2 = listOf( | ||
| DataSchemaWithAnyFrame(gps), | ||
| ).toDataFrame() | ||
| listOf(DataSchemaWithAnyFrame(gps)) | ||
| .toDataFrame() | ||
| .alsoDebug("df2:") | ||
| .convertTo<DataSchemaWithAnyFrame>() | ||
| } | ||
|
|
||
| df2.convertTo<DataSchemaWithAnyFrame>() | ||
| @Test | ||
| fun `convert df with preserved AnyFrame containing null and gps to itself`() { | ||
| val gps = gpsFrame() | ||
|
|
||
| val df3 = listOf( | ||
| listOf( | ||
| DataSchemaWithAnyFrame(null), | ||
| DataSchemaWithAnyFrame(gps), | ||
| ).toDataFrame { properties { preserve(DataFrame::class) } } | ||
| .alsoDebug("df3 before convert:") | ||
| .convertTo<DataSchemaWithAnyFrame>() | ||
| } | ||
|
|
||
| df3.convertTo<DataSchemaWithAnyFrame>() | ||
|
|
||
| val df4 = listOf( | ||
| @Test | ||
| fun `convert df with preserved null AnyFrame to itself`() { | ||
| listOf( | ||
| DataSchemaWithAnyFrame(null), | ||
| ).toDataFrame { properties { preserve(DataFrame::class) } } | ||
| .alsoDebug("df4 before convert:") | ||
| .convertTo<DataSchemaWithAnyFrame>() | ||
| } | ||
|
|
||
| df4.convertTo<DataSchemaWithAnyFrame>() | ||
| @Test | ||
| fun `convert raw df with AnyFrame column to itself`() { | ||
| val locations = locationsFrame() | ||
| val gps = gpsFrame() | ||
|
|
||
| val df5a: DataFrame<*> = dataFrameOf( | ||
| val df: DataFrame<*> = dataFrameOf( | ||
| columnOf(locations, gps, null).named("dfs"), | ||
| ).alsoDebug("df5a:") | ||
|
|
||
| df5a.convertTo<DataSchemaWithAnyFrame>() | ||
| df.convertTo<DataSchemaWithAnyFrame>() | ||
| } | ||
|
|
||
| @Test | ||
| fun `convert df with preserved mixed AnyFrame values to itself repeatedly`() { | ||
| val locations = locationsFrame() | ||
| val gps = gpsFrame() | ||
|
|
||
| val df5 = listOf( | ||
| listOf( | ||
| DataSchemaWithAnyFrame(null), | ||
| DataSchemaWithAnyFrame(locations), | ||
| DataSchemaWithAnyFrame(gps), | ||
| ).toDataFrame { properties { preserve(DataFrame::class) } } | ||
| .alsoDebug("df5 before convert:") | ||
|
|
||
| df5.convertTo<DataSchemaWithAnyFrame>() | ||
| .convertTo<DataSchemaWithAnyFrame>() | ||
| .alsoDebug("df5 after convert:") | ||
| .convertTo<DataSchemaWithAnyFrame>() | ||
| .alsoDebug("df5 after second convert:") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FieldKind.ofis a very strange factory function... Is it this way because it's used elsewhere? like in the compiler plugin? :)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, it is used there