`na.rm` or something similar for aggregations
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Start by reviewing the aggregation entry point shown in the issue, especially f.B.first(), and compare its current null behavior with the sort(..., na_position='last') workaround. Define the intended behavior and parameter naming for first and other aggregations, then verify the provided grouped examples against the chosen semantics.
Written by the indexing model from the issue text.
Description
Not sure if there is an existing ticket, so creating this. Adding a na.rm(similar to R) or skipna (pandas flavour) parameter in aggregations might be useful
I observed this in functions like first:
from datatable import dt, f, by, sort
from numpy import nan
DT = dt.Frame([{'A': 1, 'B': 'a', 'C': 5.0},
{'A': 1, 'B': 'a', 'C': nan},
{'A': 2, 'B': None, 'C': 4.0},
{'A': 2, 'B': 'b', 'C': 4.0},
{'A': 2, 'B': 'b', 'C': nan},
{'A': 3, 'B': 'c', 'C': 9.0},
{'A': 3, 'B': None, 'C': nan},
{'A': 3, 'B': 'd', 'C': nan},
{'A': 3, 'B': None, 'C': 9.0},
{'A': 4, 'B': 'e', 'C': 8.0},
{'A': 4, 'B': 'e', 'C': nan},
{'A': 5, 'B': None, 'C': 2.0},
{'A': 6, 'B': 'h', 'C': nan},
{'A': 6, 'B': 'h', 'C': nan}])
DT
| A B C
| int64 str32 float64
-- + ----- ----- -------
0 | 1 a 5
1 | 1 a NA
2 | 2 NA 4
3 | 2 b 4
4 | 2 b NA
5 | 3 c 9
6 | 3 NA NA
7 | 3 d NA
8 | 3 NA 9
9 | 4 e 8
10 | 4 e NA
11 | 5 NA 2
12 | 6 h NA
13 | 6 h NA
[14 rows x 3 columns]
# returns the exact first value, even if it is a null
DT[:, f.B.first(), 'A']
| A B
| int64 str32
-- + ----- -----
0 | 1 a
1 | 2 NA
2 | 3 c
3 | 4 e
4 | 5 NA
5 | 6 h
[6 rows x 2 columns]
# a workaround is with sort
# this might be limiting in scenarios where you do not need the sort
# or you have other columns and the sorting affects your output/analysis
DT[:, f.B.first(), 'A', sort(f.B, na_position='last')]
| A B
| int64 str32
-- + ----- -----
0 | 1 a
1 | 2 b
2 | 3 c
3 | 4 e
4 | 5 NA
5 | 6 h
[6 rows x 2 columns]
# a cleaner, more readable option, and hopefully performant would be sth similar:
DT[:, f.B.first(skipna=True), 'A']
| A B
| int64 str32
-- + ----- -----
0 | 1 a
1 | 2 b
2 | 3 c
3 | 4 e
4 | 5 NA
5 | 6 h
[6 rows x 2 columns]
Another option might be to change the semantics for first/last to show non-null values if they exist.
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 164
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from h2oai/datatable
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
Similar issues
-
comp-s3queue
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
ClickHouse/ClickHouse#137649 ·
Maintainers usually reply within 1 day
-
Clear params.inputs in dials.indexPossibly taken @phyy-nx claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
dials/dials#3361 · 1 comment ·
Maintainers usually reply within 1 day
-
difficulty:easy prio:low type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
NatronGitHub/Natron#2405 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 71/100
facebookexperimental/semcode#195 ·
Maintainers usually reply within 2 days
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100