-
Notifications
You must be signed in to change notification settings - Fork 63
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
Add GroupBy variable converter in Jupyter #663
base: master
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -7,14 +7,19 @@ import org.jetbrains.kotlinx.jupyter.api.VariableName | |
* Class representing generated code declarations for a [Marker]. | ||
* | ||
* @param declarations The generated code. | ||
* @param converter Needs to provide additional info (name) from org.jetbrains.dataframe.impl.codeGen.CodeGenerator to its callers | ||
* But at the same time name doesn't make sense for GroupBy where code to be executed contains two declarations | ||
* @param converter Optional converter for the [Marker], such as a [org.jetbrains.kotlinx.dataframe.api.cast], often used for Jupyter. | ||
*/ | ||
public data class CodeWithConverter(val declarations: Code, val converter: (VariableName) -> Code = EmptyConverter) { | ||
public data class CodeWithConverter<T : CodeConverter>( | ||
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 most functions return a 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. For GroupBy i need to combine names of two generated interfaces together for cast, and so CodeWithConverter provides this additional info. This parameter doesn't make sense for other usages, so there we use more generic CodeWithWithConverter<*> |
||
val declarations: Code, | ||
val converter: T | ||
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. maybe it's an idea to rename this variable or rework it a bit, because looking at this with new eyes, even with the documentation, I have no idea what's going on 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. Idk, hard to tell more than expressed in the code itself. Basically CodeWithConverter is all the information that dataframe integration needs to generate except name of the variable being updated. Variable name is provided by the caller due to separation of concerns. So there's hardly any special "domain" meaning behind it |
||
) { | ||
|
||
public companion object { | ||
public const val EmptyDeclarations: Code = "" | ||
public val EmptyConverter: (VariableName) -> Code = { it } | ||
public val Empty: CodeWithConverter = CodeWithConverter(EmptyDeclarations, EmptyConverter) | ||
public val EmptyConverter: CodeConverter = CodeConverter { it } | ||
public val Empty: CodeWithConverter<CodeConverter> = CodeWithConverter(EmptyDeclarations, EmptyConverter) | ||
} | ||
|
||
val hasDeclarations: Boolean get() = declarations.isNotBlank() | ||
|
@@ -27,3 +32,19 @@ public data class CodeWithConverter(val declarations: Code, val converter: (Vari | |
else -> declarations + "\n" + converter(name) | ||
} | ||
} | ||
|
||
public sealed interface CodeConverter : (VariableName) -> Code | ||
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. This probably needs docs to explain what it does/should do. As it's a foreign concept and essentially just a String->String, which doesn't tell much. Maybe it could steal some docs from |
||
|
||
public class CodeConverterImpl(private val f: (VariableName) -> Code) : CodeConverter { | ||
override fun invoke(p1: VariableName): Code { | ||
return f(p1) | ||
} | ||
} | ||
|
||
public fun CodeConverter(f: (VariableName) -> Code): CodeConverter = CodeConverterImpl(f) | ||
|
||
public class ProvidedCodeConverter(public val markerName: String) : CodeConverter { | ||
override fun invoke(p1: VariableName): Code { | ||
return "$p1.cast<$markerName>()" | ||
} | ||
} |
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.
there are two
@param converter
s now