-
Notifications
You must be signed in to change notification settings - Fork 81
countDistinct overloads on GroupBy
#1875
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
Open
Allex-Nik
wants to merge
6
commits into
master
Choose a base branch
from
count-distinct-on-group-by
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2d747c2
Add `countDistinct` overloads on `GroupBy` and KDocs for them
Allex-Nik 7718511
Add tests for `countDistinct` overloads on `GroupBy`
Allex-Nik d243c71
Update website documentation for the `countDistinct` function because…
Allex-Nik 048334a
Update `groupBy` website documentation and KDocs because of new `coun…
Allex-Nik e4f4392
Remove unused import in `Access.kt`
Allex-Nik 43c51cf
Fixes to `countDistinct` and `groupBy` documentation after review
Allex-Nik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/countDistinct.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| package org.jetbrains.kotlinx.dataframe.api | ||
|
|
||
| import io.kotest.matchers.shouldBe | ||
| import org.jetbrains.kotlinx.dataframe.nrow | ||
| import org.junit.Test | ||
|
|
||
| class CountDistinctTests { | ||
|
|
||
| private val df = dataFrameOf( | ||
| "name" to columnOf("Alice", "Alice", "Bob", "Charlie"), | ||
| "age" to columnOf(15, 15, 20, 25), | ||
| "group" to columnOf(1, 1, 1, 2), | ||
| ) | ||
|
|
||
| @Test | ||
| fun `countDistinct on GroupBy`() { | ||
| val result = df.groupBy("group").countDistinct() | ||
| val expected = dataFrameOf( | ||
| "group" to columnOf(1, 2), | ||
| "countDistinct" to columnOf(2, 1), | ||
| ) | ||
| result shouldBe expected | ||
| } | ||
|
|
||
| @Test | ||
| fun `countDistinct on GroupBy with custom result name`() { | ||
| val result = df.groupBy("group").countDistinct("unique") | ||
| val expected = dataFrameOf( | ||
| "group" to columnOf(1, 2), | ||
| "unique" to columnOf(2, 1), | ||
| ) | ||
| result shouldBe expected | ||
| } | ||
|
|
||
| @Test | ||
| fun `countDistinct on GroupBy with one unique row`() { | ||
| val df = dataFrameOf( | ||
| "name" to columnOf("Alice", "Alice", "Alice"), | ||
| "age" to columnOf(15, 15, 15), | ||
| "group" to columnOf(1, 1, 1), | ||
| ) | ||
| val result = df.groupBy("group").countDistinct() | ||
| val expected = dataFrameOf( | ||
| "group" to columnOf(1), | ||
| "countDistinct" to columnOf(1), | ||
| ) | ||
| result shouldBe expected | ||
| } | ||
|
|
||
| // TODO: check columns as well when #1531 is fixed | ||
|
Allex-Nik marked this conversation as resolved.
|
||
| @Test | ||
| fun `countDistinct on empty GroupBy`() { | ||
| df | ||
| .drop(df.nrow) | ||
| .groupBy("group").countDistinct() | ||
| .count() shouldBe 0 | ||
| } | ||
|
|
||
| @Test | ||
| fun `countDistinct on GroupBy with nulls`() { | ||
| val result = df | ||
| .append(null, null, 1) | ||
| .groupBy("group").countDistinct() | ||
| val expected = dataFrameOf( | ||
| "group" to columnOf(1, 2), | ||
| "countDistinct" to columnOf(3, 1), | ||
| ) | ||
| result shouldBe expected | ||
| } | ||
|
|
||
| @Test | ||
| fun `countDistinct on GroupBy with null group key`() { | ||
| val result = df | ||
| .append("Dave", 30, null) | ||
| .groupBy("group").countDistinct() | ||
| val expected = dataFrameOf( | ||
| "group" to columnOf(1, 2, null), | ||
| "countDistinct" to columnOf(2, 1, 1), | ||
| ) | ||
| result shouldBe expected | ||
| } | ||
|
|
||
| @Test | ||
| fun `countDistinct on GroupBy with columns selector`() { | ||
| val result = df.groupBy("group").countDistinct { "name"<String>() } | ||
| val expected = dataFrameOf( | ||
| "group" to columnOf(1, 2), | ||
| "countDistinct" to columnOf(2, 1), | ||
| ) | ||
| result shouldBe expected | ||
| } | ||
|
|
||
| @Test | ||
| fun `countDistinct on GroupBy with columns selector (not distinct only by selected column)`() { | ||
| val df = dataFrameOf( | ||
| "name" to columnOf("Alice", "Bob", "Charlie"), | ||
| "age" to columnOf(15, 15, 20), | ||
| "group" to columnOf(1, 1, 2), | ||
| ) | ||
| val result = df.groupBy("group").countDistinct { "age"<Int>() } | ||
| val expected = dataFrameOf( | ||
| "group" to columnOf(1, 2), | ||
| "countDistinct" to columnOf(1, 1), | ||
| ) | ||
| result shouldBe expected | ||
| } | ||
|
|
||
| @Test | ||
| fun `countDistinct on GroupBy with multiple columns selector`() { | ||
| val df = dataFrameOf( | ||
| "name" to columnOf("Alice", "Alice", "Bob", "Charlie"), | ||
| "age" to columnOf(15, 15, 20, 25), | ||
| "group" to columnOf(1, 1, 1, 2), | ||
| "city" to columnOf("London", "Moscow", "London", "Paris"), | ||
| ) | ||
| val result = df.groupBy("group").countDistinct { "name"<String>() and "age"<Int>() } | ||
| val expected = dataFrameOf( | ||
| "group" to columnOf(1, 2), | ||
| "countDistinct" to columnOf(2, 1), | ||
| ) | ||
| result shouldBe expected | ||
| } | ||
|
|
||
| @Test | ||
| fun `countDistinct on grouped DataFrame with columns selector and custom result name`() { | ||
| val result = df.groupBy("group").countDistinct(resultName = "unique") { "name"<String>() } | ||
| val expected = dataFrameOf( | ||
| "group" to columnOf(1, 2), | ||
| "unique" to columnOf(2, 1), | ||
| ) | ||
| result shouldBe expected | ||
| } | ||
|
|
||
| @Test | ||
| fun `countDistinct on grouped DataFrame with multiple columns selector with nulls`() { | ||
| val result = df | ||
| .append(null, null, 1) | ||
| .groupBy("group") | ||
| .countDistinct { "name"<String>() and "age"<Int>() } | ||
| val expected = dataFrameOf( | ||
| "group" to columnOf(1, 2), | ||
| "countDistinct" to columnOf(3, 1), | ||
| ) | ||
| result shouldBe expected | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.