Skip to content

Commit 2819a77

Browse files
authored
Merge pull request #651 from Kotlin/docs-fixes
Changed documentation regarding extension properties api
2 parents 2974f4d + dcfbe7f commit 2819a77

File tree

7 files changed

+32
-40
lines changed

7 files changed

+32
-40
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
@@ -120,7 +120,7 @@ internal interface AccessApi {
120120
*
121121
* For example:
122122
* ```kotlin
123-
* val df = DataFrame.read("titanic.csv")
123+
* val df /* : AnyFrame */ = DataFrame.read("titanic.csv")
124124
* ```
125125
*/
126126
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
@@ -142,7 +142,7 @@ class ApiLevels {
142142
@TransformDataFrameExpressions
143143
fun extensionProperties1() {
144144
// SampleStart
145-
val df = DataFrame.read("titanic.csv")
145+
val df /* : AnyFrame */ = DataFrame.read("titanic.csv")
146146
// SampleEnd
147147
}
148148
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
package org.jetbrains.kotlinx.dataframe.samples.api
22

33
import org.jetbrains.kotlinx.dataframe.AnyFrame
4+
import org.jetbrains.kotlinx.dataframe.DataFrame
45
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
6+
import org.jetbrains.kotlinx.dataframe.api.take
57
import org.jetbrains.kotlinx.dataframe.explainer.WritersideFooter
68
import org.jetbrains.kotlinx.dataframe.explainer.WritersideStyle
9+
import org.jetbrains.kotlinx.dataframe.io.read
710
import org.jetbrains.kotlinx.dataframe.io.toStandaloneHTML
811
import org.junit.Test
912
import java.io.File
1013

1114
// To display code together with a table, we can use TransformDataFrameExpressions annotation together with korro
1215
// This class provides an ability to save only a table that can be embedded anywhere in the documentation
1316
class OtherSamples {
17+
1418
@Test
1519
fun extensionPropertiesApi1() {
16-
val df = dataFrameOf("example")(123)
20+
val df = DataFrame.read("../data/titanic.csv", delimiter = ';').take(5)
1721
writeTable(df, "extensionPropertiesApi1")
1822
}
1923

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
@@ -142,7 +142,7 @@ class ApiLevels {
142142
@TransformDataFrameExpressions
143143
fun extensionProperties1() {
144144
// SampleStart
145-
val df = DataFrame.read("titanic.csv")
145+
val df /* : AnyFrame */ = DataFrame.read("titanic.csv")
146146
// SampleEnd
147147
}
148148
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
package org.jetbrains.kotlinx.dataframe.samples.api
22

33
import org.jetbrains.kotlinx.dataframe.AnyFrame
4-
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
4+
import org.jetbrains.kotlinx.dataframe.DataFrame
5+
import org.jetbrains.kotlinx.dataframe.api.take
56
import org.jetbrains.kotlinx.dataframe.explainer.WritersideFooter
67
import org.jetbrains.kotlinx.dataframe.explainer.WritersideStyle
8+
import org.jetbrains.kotlinx.dataframe.io.read
79
import org.jetbrains.kotlinx.dataframe.io.toStandaloneHTML
810
import org.junit.Test
911
import java.io.File
1012

1113
// To display code together with a table, we can use TransformDataFrameExpressions annotation together with korro
1214
// This class provides an ability to save only a table that can be embedded anywhere in the documentation
1315
class OtherSamples {
16+
1417
@Test
15-
fun extensionPropertiesApi1() {
16-
val df = dataFrameOf("example")(123)
17-
writeTable(df, "extensionPropertiesApi1")
18+
fun example() {
19+
val df = DataFrame.read("../data/titanic.csv", delimiter = ';').take(5)
20+
// writeTable(df, "exampleName")
1821
}
1922

2023
private fun writeTable(df: AnyFrame, name: String) {

docs/StardustDocs/topics/apiLevels.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Here's a list of all APIs in order of increasing safety.
2828
Columns accessed by the [`KProperty`](https://kotlinlang.org/docs/reflection.html#property-references) of some class.
2929
The name and type of column should match the name and type of property, respectively.
3030

31-
* [**Extension Properties API**](extensionPropertiesApi.md)
31+
* [**Extension Properties API**](extensionPropertiesApi.md) <br/>
3232
Extension access properties are generated based on the dataframe schema. The name and type of properties are inferred
3333
from the name and type of the corresponding columns.
3434

@@ -114,7 +114,7 @@ val passengers = DataFrame.read("titanic.csv")
114114
<!---FUN extensionProperties1-->
115115

116116
```kotlin
117-
val df = DataFrame.read("titanic.csv")
117+
val df /* : AnyFrame */ = DataFrame.read("titanic.csv")
118118
```
119119

120120
<!---END-->
Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,24 @@
1-
[//]: # (title: Extension properties API)
1+
[//]: # (title: Extension Properties API)
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:
8-
9-
<!---FUN extensionProperties1-->
5+
Auto-generated extension properties are the safest and easiest way to access columns in a [`DataFrame`](DataFrame.md).
6+
They are generated based on a [dataframe schema](schemas.md),
7+
with the name and type of properties inferred from the name and type of the corresponding columns.
108

9+
Having these, it allows you to work with your dataframe like:
1110
```kotlin
12-
val df = DataFrame.read("titanic.csv")
11+
val peopleDf /* : DataFrame<Person> */ = DataFrame.read("people.csv").cast<Person>()
12+
val nameColumn /* : DataColumn<String> */ = peopleDf.name
13+
val ageColumn /* : DataColumn<Int> */ = peopleDf.personData.age
1314
```
14-
15-
<!---END-->
16-
17-
Now data can be accessed by `.` member accessor
18-
19-
<!---FUN extensionProperties2-->
20-
15+
and of course
2116
```kotlin
22-
df.add("lastName") { name.split(",").last() }
23-
.dropNulls { age }
24-
.filter { survived && home.endsWith("NY") && age in 10..20 }
17+
peopleDf.add("lastName") { name.split(",").last() }
18+
.dropNulls { personData.age }
19+
.filter { survived && home.endsWith("NY") && personData.age in 10..20 }
2520
```
2621

27-
<!---END-->
28-
29-
The `titanic.csv` file could be found [here](https://github.com/Kotlin/dataframe/blob/master/data/titanic.csv).
30-
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-
35-
Extension properties can be generated in IntelliJ IDEA using the [Kotlin DataFrame Gradle plugin](schemasGradle.md#configuration).
36-
37-
<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
39-
</warning>
22+
To find out how to use this API in your environment, check out [Working with Data Schemas](schemas.md)
23+
or jump straight to [Data Schemas in Gradle projects](schemasGradle.md),
24+
or [Data Schemas in Jupyter notebooks](schemasJupyter.md).

0 commit comments

Comments
 (0)