Skip to content

Commit 30fc68d

Browse files
Corr docs init
1 parent 6438634 commit 30fc68d

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/corr.kt

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,117 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

3+
import kotlinx.datetime.Instant
4+
import kotlinx.datetime.LocalDate
5+
import kotlinx.datetime.LocalDateTime
6+
import kotlinx.datetime.LocalTime
37
import org.jetbrains.kotlinx.dataframe.AnyCol
48
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
59
import org.jetbrains.kotlinx.dataframe.DataFrame
10+
import org.jetbrains.kotlinx.dataframe.RowColumnExpression
11+
import org.jetbrains.kotlinx.dataframe.RowValueExpression
612
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
713
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
814
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
15+
import org.jetbrains.kotlinx.dataframe.dataTypes.IFRAME
16+
import org.jetbrains.kotlinx.dataframe.dataTypes.IMG
17+
import org.jetbrains.kotlinx.dataframe.documentation.DocumentationUrls
18+
import org.jetbrains.kotlinx.dataframe.documentation.DocumentationUrls.Convert
19+
import org.jetbrains.kotlinx.dataframe.documentation.DslGrammarLink
20+
import org.jetbrains.kotlinx.dataframe.documentation.ExcludeFromSources
21+
import org.jetbrains.kotlinx.dataframe.documentation.Indent
22+
import org.jetbrains.kotlinx.dataframe.documentation.LineBreak
23+
import org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns
24+
import org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns.ColumnGroupsAndNestedColumnsMention
925
import org.jetbrains.kotlinx.dataframe.impl.api.corrImpl
26+
import java.math.BigDecimal
27+
import java.math.BigInteger
28+
import java.net.URL
1029
import kotlin.reflect.KProperty
30+
import kotlin.reflect.KType
1131
import kotlin.reflect.typeOf
1232

33+
/**
34+
* Calculates the correlation between values in the specified [columns\].
35+
*
36+
* This function does not perform the calculation immediately. Instead, it selects a primary set of columns
37+
* and returns a [Corr] object, which serves as an intermediate step in the correlation analysis.
38+
*
39+
* The [Corr] object provides two methods to perform correlation computations:
40+
* - [with][Corr.with] — allows you to specify a second set of columns and computes correlations between
41+
* the initially selected columns and this second set.
42+
* - [withItself][Corr.withItself] — computes correlations within the initially selected columns.
43+
*
44+
* Each of these methods returns a [DataFrame] where rows correspond to one set of columns, columns to the other set,
45+
* and each cell contains the correlation coefficient between the corresponding pair of columns.
46+
*
47+
* If you need to compute correlations between all columns in a DataFrame, use [DataFrame.corr()][DataFrame.corr].
48+
*
49+
* Check out [Grammar].
50+
*
51+
* @include [SelectingColumns.ColumnGroupsAndNestedColumnsMention]
52+
*
53+
* See [Selecting Columns][ConvertSelectingOptions].
54+
*
55+
* For more information: {@include [DocumentationUrls.Corr]}
56+
*/
57+
internal interface CorrDocs {
58+
59+
/**
60+
* {@comment Version of [SelectingColumns] with correctly filled in examples}
61+
* @include [SelectingColumns] {@include [SetCorrOperationArg]}
62+
*/
63+
interface ConvertSelectingOptions
64+
65+
/**
66+
* ## Corr Operation Grammar
67+
* {@include [LineBreak]}
68+
* {@include [DslGrammarLink]}
69+
* {@include [LineBreak]}
70+
*
71+
* **[`corr`][convert]**` { columnsSelector: `[`ColumnsSelector`][ColumnsSelector]` }`
72+
*
73+
* {@include [Indent]}
74+
* __`.`__[**`with`**][Corr.with]` { columnsSelector: `[`ColumnsSelector`][ColumnsSelector]` }`
75+
*
76+
* {@include [Indent]}
77+
*`| `__`.`__[**`withItself`**][Corr.withItself]`()`
78+
*/
79+
interface Grammar
80+
}
81+
82+
/** {@set [SelectingColumns.OPERATION] [corr][corr]} */
83+
@ExcludeFromSources
84+
private interface SetCorrOperationArg
85+
86+
/**
87+
* {@include [CorrDocs]}
88+
* ### This Corr Overload
89+
*/
90+
@ExcludeFromSources
91+
private interface CommonCorrDocs
92+
1393
internal fun AnyCol.isSuitableForCorr() = isSubtypeOf<Number>() || type() == typeOf<Boolean>()
1494

1595
// region DataFrame
1696

97+
/**
98+
* An intermediate class used in the [corr] operation.
99+
*
100+
* This class itself does not perform any computations — it is a transitional step
101+
* before specifying how to compute correlation.
102+
* It must be followed by one of the methods specifying correlation
103+
* computation to produce a new correlation [DataFrame].
104+
*
105+
* Each of these methods returns a [DataFrame] where rows correspond to one set of columns, columns to the other set,
106+
* and each cell contains the correlation coefficient between the corresponding pair of columns.
107+
*
108+
* Use the following methods to perform the computation:
109+
* - [with { columnsSelector }][with] – selects a second set of columns and computes correlations between
110+
* the initially selected columns and this second set.
111+
* - [withItself()][withItself] - computes correlations within the initially selected columns.
112+
*
113+
* See [Grammar][CorrDocs.Grammar] for more details.
114+
*/
17115
public data class Corr<T, C>(internal val df: DataFrame<T>, internal val columns: ColumnsSelector<T, C>)
18116

19117
public fun <T> DataFrame<T>.corr(): DataFrame<T> = corr { colsAtAnyDepth { it.isSuitableForCorr() } }.withItself()

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/DocumentationUrls.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,7 @@ internal interface DocumentationUrls {
101101

102102
/** [See `convert` on the documentation website.]({@include [Url]}/convert.html) */
103103
interface Convert
104+
105+
/** [See `convert` on the documentation website.]({@include [Url]}/corr.html) */
106+
interface Corr
104107
}

0 commit comments

Comments
 (0)