Skip to content
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

Fix dt.median() when used on a groupby context for void columns #3412

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/api/dt/median.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
Input columns.

return: Expr
f-expression having one row, and the same names, stypes and
number of columns as in `cols`.
f-expression having one row, and the same names and number of columns
as in `cols`. The column stypes are `float32` for
`float32` columns, and `float64` for all the other numeric types.

except: TypeError
The exception is raised when one of the columns from `cols`
Expand Down
3 changes: 3 additions & 0 deletions docs/releases/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
-[fix] Reducers and row-wise functions now support :attr:`void <dt.Type.void>`
columns. [#3284]

-[fix] Fixed :func:`dt.median()` when used in a groupby context with
:attr:`void <dt.Type.void>` columns. [#3411]


fread
-----
Expand Down
2 changes: 1 addition & 1 deletion src/core/expr/head_reduce_unary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ static Column compute_median(Column&& arg, const Groupby& gby) {
return Column::new_na_column(1, arg.stype());
}
switch (arg.stype()) {
case SType::VOID: return Column(new ConstNa_ColumnImpl(1));
case SType::VOID: return Column(new ConstNa_ColumnImpl(gby.size()));
case SType::BOOL:
case SType::INT8: return _median<int8_t> (std::move(arg), gby);
case SType::INT16: return _median<int16_t>(std::move(arg), gby);
Expand Down
1 change: 1 addition & 0 deletions src/core/sort.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,7 @@ RiGb group(const std::vector<Column>& columns,


void dt::ColumnImpl::sort_grouped(const Groupby& grps, Column& out) {
out.materialize(); // `SortContext::continue_sort()` requires material column
(void) out.stats();
SortContext sc(nrows(), RowIndex(), grps, /* make_groups = */ false);
sc.continue_sort(out, /* desc = */ false, /* make_groups = */ false);
Expand Down
12 changes: 9 additions & 3 deletions tests/test-reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,19 +458,25 @@ def test_mean_empty_frame():

def test_median_void():
DT = dt.Frame([None] * 10)
DT_median = DT[:, mean(f.C0)]
DT_median = DT[:, median(f.C0)]
assert_equals(DT_median, dt.Frame([None]))


def test_median_void_per_group():
DT = dt.Frame([[None, None, None, None, None], [1, 2, 1, 2, 2]])
DT_median = DT[:, mean(f.C0), by(f.C1)]
DT_median = DT[:, median(f.C0), by(f.C1)]
assert_equals(DT_median, dt.Frame(C1=[1, 2]/dt.int32, C0=[None, None]))


def test_median_nonvoid_per_void_group():
DT = dt.Frame([[None, None, None, None, None], [1, 2, 1, 2, 2]])
DT_median = DT[:, median(f.C1), by(f.C0)]
assert_equals(DT_median, dt.Frame([[None], [2]/dt.float64]))


def test_median_void_grouped():
DT = dt.Frame([[None, None, None, None, None], [1, 2, 1, 2, 2]])
DT_median = DT[:, mean(f.C0), by(f.C0)]
DT_median = DT[:, median(f.C0), by(f.C0)]
assert_equals(DT_median, dt.Frame([[None], [None]/dt.float64]))


Expand Down