Skip to content

Commit 40a8064

Browse files
committed
more explicit explanation of what happens in between cell calls in the extension properties api in notebooks
1 parent 18dbbbf commit 40a8064

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/AccessApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ internal interface AccessApi {
122122
*
123123
* For example:
124124
* ```kotlin
125-
* val df = DataFrame.read("titanic.csv")
125+
* val df /* : AnyFrame */ = DataFrame.read("titanic.csv")
126126
* ```
127127
*/
128128
interface ExtensionPropertiesApi

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/ApiLevels.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class ApiLevels {
140140
@TransformDataFrameExpressions
141141
fun extensionProperties1() {
142142
// SampleStart
143-
val df = DataFrame.read("titanic.csv")
143+
val df /* : AnyFrame */ = DataFrame.read("titanic.csv")
144144
// SampleEnd
145145
}
146146
}

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/ApiLevels.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class ApiLevels {
140140
@TransformDataFrameExpressions
141141
fun extensionProperties1() {
142142
// SampleStart
143-
val df = DataFrame.read("titanic.csv")
143+
val df /* : AnyFrame */ = DataFrame.read("titanic.csv")
144144
// SampleEnd
145145
}
146146
}

docs/StardustDocs/topics/extensionPropertiesApi.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,30 @@
22

33
<!---IMPORT org.jetbrains.kotlinx.dataframe.samples.api.ApiLevels-->
44

5-
When [`DataFrame`](DataFrame.md) is used within Jupyter Notebooks or Datalore with Kotlin Kernel,
6-
after every cell execution all new global variables of type DataFrame are analyzed and replaced
7-
with typed [`DataFrame`](DataFrame.md) wrapper with auto-generated extension properties for data access:
5+
When [`DataFrame`](DataFrame.md) is used within Jupyter/Kotlin Notebook or Datalore with the Kotlin Kernel,
6+
something special happens:
7+
After every cell execution, all new global variables of type DataFrame are analyzed and replaced
8+
with a typed [`DataFrame`](DataFrame.md) wrapper along with auto-generated extension properties for data access.
9+
For instance, say we run:
810

911
<!---FUN extensionProperties1-->
1012

1113
```kotlin
12-
val df = DataFrame.read("titanic.csv")
14+
val df /* : AnyFrame */ = DataFrame.read("titanic.csv")
1315
```
1416

1517
<!---END-->
1618

17-
Now data can be accessed by `.` member accessor
19+
In normal Kotlin code, we would now have a variable of type [`AnyFrame` (=`DataFrame<*>`)](DataFrame.md) that doesn't have any
20+
extension properties to access its columns. We would either have to define them manually or use the
21+
[`@DataSchema`](schemas.md) annotation to [generate them](schemasGradle.md#configuration).
22+
23+
By contrast, after this cell is run in a notebook, the columns of the dataframe are used as a basis
24+
to generate a hidden `@DataSchema interface TypeX`,
25+
along with extension properties like `val DataFrame<TypeX>.age` etc.
26+
Next, the `df` variable is shadowed by a new version cast to `DataFrame<TypeX>`.
27+
28+
As a result, now columns can be accessed directly on `df`!
1829

1930
<!---FUN extensionProperties2-->
2031

@@ -28,12 +39,9 @@ df.add("lastName") { name.split(",").last() }
2839

2940
The `titanic.csv` file could be found [here](https://github.com/Kotlin/dataframe/blob/master/data/titanic.csv).
3041

31-
In notebooks, extension properties are generated for [`DataSchema`](schemas.md) that is extracted from [`DataFrame`](DataFrame.md)
32-
instance after REPL line execution.
33-
After that [`DataFrame`](DataFrame.md) variable is typed with its own [`DataSchema`](schemas.md), so only valid extension properties corresponding to actual columns in DataFrame will be allowed by the compiler and suggested by completion.
34-
3542
Extension properties can be generated in IntelliJ IDEA using the [Kotlin Dataframe Gradle plugin](schemasGradle.md#configuration).
3643

3744
<warning>
38-
In notebooks generated properties won't appear and be updated until the cell has been executed. It often means that you have to introduce new variable frequently to sync extension properties with actual schema
45+
In notebooks generated properties won't appear and be updated until the cell has been executed.
46+
It often means that you have to introduce new variable frequently to sync extension properties with actual schema.
3947
</warning>

0 commit comments

Comments
 (0)