Skip to content

GroupBy Jupyter codegen #1263

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

Merged
merged 4 commits into from
Jun 23, 2025
Merged

GroupBy Jupyter codegen #1263

merged 4 commits into from
Jun 23, 2025

Conversation

Jolanrensen
Copy link
Collaborator

Fixes #1221

Uses this PR as its base: #663:

This was a long standing minor inconvenience. Having this variable in a cell1 you couldn't access k in keys in the cell2 cell1:

val groupBy = dataFrameOf("a")("1", "11", "2", "22")
    .groupBy { expr { "a"<String>().length } named "k" }

cell2:

groupBy.keys.k

Other use case is adding a new column to GroupBy

val groupBy = dataFrameOf("a")("1", "11", "2", "22")
    .groupBy { expr { "a"<String>().length } named "k" }
    .add("newCol") { 42 }
groupBy.aggregate { newCol into "newCol" }

But it's now up-to-date and contains some refactoring:

  • Refactor of CodeWithConverter -> CodeWithTypeCastGenerator. It was never really a "converter", it can just generate a casting expression for an expression, so...
  • I created the TypeCastGenerator interface (the name can still change of course). It has a specific implementation that uses the cast<>() functions from the DataFrame API (instead of having string literals in different places) which also supports multiple type-arguments (for GroupBy).
  • I did some additional renaming like markerName -> targetTypeName since it makes it easier to understand without a grasp of the larger context.

…ver a "converter", it can just generate a casting expression for an expression, so I created the `TypeCastGenerator` interface. It has a specific implementation that uses the cast<>() functions from the DataFrame API (instead of having string literals in different places) which also supports multiple arguments (for GroupBy). Did some additional renaming like `markerName` -> `targetTypeName` since it makes it easier to understand without a grasp of the larger context.
when (instance) {
is AnyCol -> updateAnyColVariable(instance, property, codeGen)
is ColumnGroup<*> -> updateColumnGroupVariable(instance, property, codeGen)
is AnyRow -> updateAnyRowVariable(instance, property, codeGen)
is AnyFrame -> updateAnyFrameVariable(instance, property, codeGen)
is ImportDataSchema -> updateImportDataSchemaVariable(instance, property)
is GroupBy<*, *> -> updateGroupByVariable(instance, property, codeGen)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have one question here: do we need the same support for Pivot as for GroupBy? At least create a ticket and make a separate fix? or validate with test

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually yes!
We can try to test this by writing val pivot dataFrameOf(...).pivot { ... } and trying to access columns in the cell below.

#1268

@Jolanrensen Jolanrensen merged commit 13ff0c5 into master Jun 23, 2025
6 checks passed
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.

Missing jupyter codegen for GroupBy type
3 participants