Skip to content

Commit

Permalink
Add dt.prod() test for a grouped column, by() docs adjustment (#3396
Browse files Browse the repository at this point in the history
)

- the fix for #3390 has been already pushed as a part of #3388, here we merely add a corresponding test;
- as of #2472, `f[:]` excludes the groupby columns, in this PR we make the corresponding adjustments to the docs. 

Closes #3390
  • Loading branch information
samukweku authored Dec 14, 2022
1 parent cd41450 commit 81d1f9b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
11 changes: 6 additions & 5 deletions docs/api/dt/by.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
will select those rows where column A reaches its peak value within
each group (there could be multiple such rows within each group).

- Before ``j`` is evaluated, the ``by()`` clause adds all its columns
at the start of ``j`` (unless ``add_columns`` argument is ``False``). If
``j`` is a "select-all" slice (i.e. ``:``), then those columns will
also be excluded from the list of all columns so that they will be
present in the output only once.
- Before ``j`` is evaluated, the ``by()`` clause adds all the groupby
columns at the start of ``j`` (unless ``add_columns`` argument is
``False``). If ``j`` is a "select-all" slice (i.e. ``:`` or
``f[:]``), then the groupby columns will be excluded
from the list of all columns, so that they will be present in the output
only once.

- During evaluation of ``j``, the reducer functions, such as
:func:`min`, :func:`sum`, etc, will be evaluated by-group, that is
Expand Down
2 changes: 1 addition & 1 deletion docs/api/dt/f.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
- ``f.A`` means "column A" of frame ``DT``;
- ``f[2]`` means "3rd colum" of frame ``DT``;
- ``f[int]`` means "all integer columns" of ``DT``;
- ``f[:]`` means "all columns" of ``DT``.
- ``f[:]`` means "all columns" of ``DT`` not including :func:`by` columns, however.


See also
Expand Down
10 changes: 10 additions & 0 deletions tests/test-groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ def test_reduce_sum_same_column():
frame_integrity_check(f1)
assert_equals(f1, dt.Frame({"ints" : [0, 1, 2], "sum" : [0, 2, 2]/dt.int64}))


def test_reduce_prod():
f0 = dt.Frame({"color": ["red", "blue", "green", "red", "green"],
"size": [5, 2, 7, 13, -1]})
Expand All @@ -301,6 +302,15 @@ def test_reduce_prod():
[2, -7, 65]]


def test_reduce_prod_same_column():
# See issue #3390
f0 = dt.Frame({"ints" : [0, -1, 2, 2, -1, 2]})
f1 = f0[:, {"prod" : prod(f.ints)}, f.ints]
frame_integrity_check(f1)
assert_equals(f1, dt.Frame({"ints" : [-1, 0, 2], "prod" : [1, 0, 8]/dt.int64}))



#-------------------------------------------------------------------------------
# Groupby on large datasets
#-------------------------------------------------------------------------------
Expand Down

0 comments on commit 81d1f9b

Please sign in to comment.