Skip to content

Add documentation and tests for DataColumnArithmetics.kt#1769

Open
Allex-Nik wants to merge 4 commits intomasterfrom
data-column-arithmetics-docs-tests
Open

Add documentation and tests for DataColumnArithmetics.kt#1769
Allex-Nik wants to merge 4 commits intomasterfrom
data-column-arithmetics-docs-tests

Conversation

@Allex-Nik
Copy link
Copy Markdown
Collaborator

@Allex-Nik Allex-Nik commented Mar 26, 2026

Fixes #530

Added:

  • KDocs
  • Tests
  • Website documentation

for DataColumnArithmetics.kt

* using the logical `not` operation: `true` becomes `false`, and `false` becomes `true`.}
* @set [NOT_RETURN] A [ColumnReference] containing the negated [Boolean] values of this [reference][ColumnReference].
*/
public operator fun ColumnReference<Boolean>.not(): ColumnReference<Boolean> = map { !it }
Copy link
Copy Markdown
Collaborator Author

@Allex-Nik Allex-Nik Mar 26, 2026

Choose a reason for hiding this comment

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

Should we reuse the example for DataColumn (as one of implementations) here and in other cases when ColumnReference is used?


## When useful

In most transformations, these column operations are usually not the preferred approach in Kotlin DataFrame,
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not sure if I conveyed the idea in sufficient detail. Is there anything that should be added?

@Allex-Nik Allex-Nik added documentation Improvements or additions to documentation (not KDocs) KDocs Improvements or additions to KDocs tests Something related to the JUnit tests, integration tests or testing infrastructure labels Mar 26, 2026
* @include [NumberPlusColumnDocs]
* @set [NUMBER_PLUS_COLUMN_NUMBER_TYPE] [Double]
* @set [NUMBER_PLUS_COLUMN_EXAMPLE_NUMBER] 10.0
* @set [NUMBER_PLUS_COLUMN_SEE_ALSO] [minus][DataColumn.minus], [times][DataColumn.times], [div][DataColumn.div]
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This refers to DataColumn<Int>.minus(value: Int): DataColumn<Int>.
Isn't there any way to refer to Double.minus(column: DataColumn<Int>) instead?

[minus][Double.minus] doesn't work because it refers to public final operator fun minus(other: Byte): Double from Kotlin.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nope... [Double.minus] is the closest we can get. If there's multiple matches, the 2026 IDE does give you a list to pick, but there's no way to specify an exact function in KDocs :/ (yet!)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Allex-Nik Allex-Nik marked this pull request as ready for review March 26, 2026 15:47
Copy link
Copy Markdown
Collaborator

@Jolanrensen Jolanrensen left a comment

Choose a reason for hiding this comment

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

thanks! :D

* ```kotlin
* // Given a DataFrame of financial transactions,
* // create a column indicating which transactions failed
* val failed = !df.isSuccessful.rename("failed")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

hmm, maybe this example could also include an example from inside the selection DSL

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

actually, it's not often we work with columns outside a dataframe. we could :) but it's probably best to show it inside a dataframe operation first


/**
* @include [NotDocs]
* @set [NOT_NULL_NOTE] Each `null` value in the original [DataColumn] is preserved.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

careful mixing block- and inline tags, you can see when you place your cursor here which text is included by this @set tag. Because it doesn't have {} around it, the {@set } below it becomes part of the [NOT_NULL_NOTE]. (okay in practice, the {@set } will be read first and removed from the KDOC, so nothing of it actually enters [NOT_NULL_NOTE], but mixing scopes it generally only a good idea if it's intentional)

In this case, I would turn them all into block tags (so without {}), then each tag continues until it encounters another or the end of the kdoc is reached. Same as @param and @return :)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the same happens in other places

* @include [NumberPlusColumnDocs]
* @set [NUMBER_PLUS_COLUMN_NUMBER_TYPE] [Double]
* @set [NUMBER_PLUS_COLUMN_EXAMPLE_NUMBER] 10.0
* @set [NUMBER_PLUS_COLUMN_SEE_ALSO] [minus][DataColumn.minus], [times][DataColumn.times], [div][DataColumn.div]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nope... [Double.minus] is the closest we can get. If there's multiple matches, the 2026 IDE does give you a list to pick, but there's no way to specify an exact function in KDocs :/ (yet!)

* @include [NumberPlusColumnDocs]
* @set [NUMBER_PLUS_COLUMN_NUMBER_TYPE] [Double]
* @set [NUMBER_PLUS_COLUMN_EXAMPLE_NUMBER] 10.0
* @set [NUMBER_PLUS_COLUMN_SEE_ALSO] [minus][DataColumn.minus], [times][DataColumn.times], [div][DataColumn.div]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

<!---IMPORT org.jetbrains.kotlinx.dataframe.samples.api.Modify-->

Kotlin DataFrame provides operators for applying simple arithmetic, logical, string, and comparison operations
to [`DataColumn`](DataColumn.md) and `ColumnReference` values. These operations include, for example, adding a value to a column,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

"adding value to each cell in a column"?

Converts each element of the column to a String and concatenates it with the value.

```kotlin
df.amount + "€"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think only "€" + df.amount would make sense, but that might be something we cannot overload... right?

df.amount + "€"
```

`null` values are converted to the string `"null"`.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

vote to change!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation (not KDocs) KDocs Improvements or additions to KDocs tests Something related to the JUnit tests, integration tests or testing infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document and test DataColumnArithmetics.kt

3 participants