Skip to content

Updated website docs, added KDocs and tests for valueCounts - #2031

Open
Allex-Nik wants to merge 3 commits into
masterfrom
value-counts-docs-tests
Open

Updated website docs, added KDocs and tests for valueCounts#2031
Allex-Nik wants to merge 3 commits into
masterfrom
value-counts-docs-tests

Conversation

@Allex-Nik

@Allex-Nik Allex-Nik commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1992
Helps #898

@Allex-Nik
Allex-Nik force-pushed the value-counts-docs-tests branch from f718b42 to 6fe4698 Compare August 14, 2026 13:11
@Allex-Nik
Allex-Nik force-pushed the value-counts-docs-tests branch from 6fe4698 to bb39a6b Compare August 14, 2026 16:53
@Allex-Nik
Allex-Nik requested a review from Jolanrensen August 14, 2026 16:53

@Jolanrensen Jolanrensen left a comment

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.

Overall good :)

* Otherwise, the counted values keep the order of their first occurrence.
* @param [ascending\] The sorting direction. If `false` (default), the most frequent values come first.
* Only used when [sort\] is `true`.
* @param [dropNA\] If `true` (default), [`NA`][NA] values (`null`s and `NaN`s) are not counted

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.

you can use {@include [NALink]}

@Allex-Nik Allex-Nik Aug 15, 2026

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.

"[NA][NA]" is resolved to the same internal typealias NA = Nothing with its docs, I haven't seen any difference :)
Is using {@include [NALink]} better?

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.

it indeed resolves the same :) It's just a reusable link. If we ever decide to change the name, the links that are reused will change too

* and a row is not counted at all if any of its selected values is [`NA`][NA].
*
* See also:
* - [valueCounts][DataColumn.valueCounts] — counts of unique values in a single [DataColumn].

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.

not 100% whether we should already put the aliases in backticks, but I can do that in my PR if this one is merged first :)

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.

I've added the backticks to the aliases :)

*
* The resulting [DataFrame] contains:
* - the column with the distinct values of the original [DataColumn]
* - a new [Int] column ([resultColumn]) with the number of occurrences of each value.

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 would rewrite this part about "resultColumn" to say that it is named "count" by default unless this name is overridden by resultColumn. Same in CommonValueCountsDocs

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.

come to think of it... if resultColumn is supplied, the cast to DataFrame<ValueCount> is broken... Maybe it makes sense to add an overload without resultColumn that returns DataFrame<ValueCount> and one with resultColumn that simply returns AnyFrame :) we could make a separate issue for it... but it's a quick fix imo, wdyt?

@Allex-Nik Allex-Nik Aug 15, 2026

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.

We can do that. It also should not break the DataFrame IDEA plugin as far as I see. The only thing that bothers me is that providing resultColumn is not the only way to make the name of the column with counts not "count": if the name of the receiver is the same as the name of the column with counts (so the new column becomes count1), the cast will also break, and another overload will not fix it, right? It's a rare case though

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.

Damn, you're right. No, only the compiler plugin can fix that :)

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.

It seems compiler plugin support is missing for both DataColumn<T>.valueCounts and DataFrame<T>.valueCounts(vararg columns: String...)

* ```
*
* @include [ValueCountsParams]
* @param [columns] The [ColumnsSelector] used to select the columns whose distinct value combinations

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.

'optional [ColumnsSelector]'. I'd repeat here the "if null or not supplied, all columns are selected" statement :)

* ```
*
* @include [ValueCountsParams]
* @param [columns] The names of the columns whose distinct value combinations are counted.

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.

also optional. If unsupplied, all columns will be selected (yes, it will resolve to the other overload, but to the user will not notice this difference)

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.

also, this param should be the first :) above ValueCountsParams

* `dropNA: Boolean = true` — doesn't include counts of [`NA`](nanAndNa.md) values
* `resultColumn: String = "count"` — name of the column with counts
* `columns = all` — columns to use when counting unique combinations

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'd put a small introduction here. Something like "For example:"

df
// SampleEnd
.format().perRowCol { row, _ ->
if (row.name == "Alice" && row.age == 15) background(aliceColor) and textColor(black) else 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.

I wonder if it makes sense to give the Alice, null row a different color to annotate it's being considered too, but dropNA makes it be skipped. (The text could be stricken through maybe? Or maybe not since it's used in the second example, let's see what looks best :) )

df.valueCounts(dropNA = false)
// SampleEnd
.format().perRowCol { row, _ ->
if (row.name == "Alice" && row.age == null) background(aliceColor) and textColor(black) else 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.

Ah yes and then here the Alice, 15 row could be aliceColor and the Alice, null row could be the same color as Alice, null above :)

private typealias ValueCountsParams = Nothing

/**
* Returns a [DataFrame] containing counts of unique rows (or combinations of selected values) in this [DataFrame].

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 counts

*
* All summary statistics: {@include [DocumentationUrls.Statistics]}
*
* ### This ValueCounts Overload

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.

*Value Counts (like a title) or *valueCounts referring to the operation name, the name of the function

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add KDocs for valueCounts APIs

2 participants