Skip to content

Commit 072093f

Browse files
committed
review
1 parent 9d86f51 commit 072093f

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Add_Group_Number.enso

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
private
2+
13
from Standard.Base import all
24
import Standard.Base.Errors.Common.Unsupported_Argument_Types
35
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
@@ -28,7 +30,7 @@ add_group_number (table:Table) (grouping_method:Grouping_Method) (name:Text) (fr
2830
grouping = _prepare_group_by table problem_builder group_by
2931
AddGroupNumber.numberGroupsUnique table.row_count from step grouping java_problem_aggregator
3032
Grouping_Method.Equal_Count group_count order_by ->
31-
_illegal_if (group_count==0) "group_count must be at least 1" <|
33+
_illegal_if (group_count < 1) "group_count must be at least 1" <|
3234
ordering = _prepare_ordering table problem_builder order_by
3335
AddGroupNumber.numberGroupsEqualCount table.row_count group_count from step (ordering.at 0) (ordering.at 1) java_problem_aggregator
3436
new_column = Column.from_storage name new_storage

std-bits/table/src/main/java/org/enso/table/operations/AddGroupNumber.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static Storage<?> numberGroupsUnique(
3030

3131
var groupNumberIterator = new StepIterator(start, step);
3232

33-
long[] numbers = new long[(int) numRows];
33+
long[] numbers = new long[Math.toIntExact(numRows)];
3434

3535
Storage<?>[] groupingStorages =
3636
Arrays.stream(groupingColumns).map(Column::getStorage).toArray(Storage[]::new);
@@ -59,7 +59,7 @@ public static Storage<?> numberGroupsEqualCount(
5959
Column[] orderingColumns,
6060
int[] directions,
6161
ProblemAggregator problemAggregator) {
62-
long[] numbers = new long[(int) numRows];
62+
long[] numbers = new long[Math.toIntExact(numRows)];
6363

6464
var equalCountGenerator = new EqualCountGenerator(start, step, numRows, groupCount);
6565

@@ -72,7 +72,7 @@ public static Storage<?> numberGroupsEqualCount(
7272
Arrays.stream(orderingColumns).map(Column::getStorage).toArray(Storage[]::new);
7373
List<OrderedMultiValueKey> keys =
7474
new ArrayList<>(
75-
IntStream.range(0, (int) numRows)
75+
IntStream.range(0, Math.toIntExact(numRows))
7676
.mapToObj(i -> new OrderedMultiValueKey(orderingStorages, i, directions))
7777
.toList());
7878
keys.sort(null);
@@ -104,7 +104,7 @@ public long next() {
104104
private static class EqualCountGenerator {
105105
private final long start;
106106
private final long step;
107-
private long current = 0;
107+
private long currentIndex = 0;
108108
private final long groupSize;
109109

110110
public EqualCountGenerator(long start, long step, long totalCount, long numgroups) {
@@ -114,8 +114,8 @@ public EqualCountGenerator(long start, long step, long totalCount, long numgroup
114114
}
115115

116116
public long next() {
117-
long toReturn = Math.addExact(start, Math.multiplyExact(step, (current / groupSize)));
118-
current = Math.addExact(current, 1L);
117+
long toReturn = Math.addExact(start, Math.multiplyExact(step, (currentIndex / groupSize)));
118+
currentIndex = Math.addExact(currentIndex, 1L);
119119
return toReturn;
120120
}
121121
}

test/Table_Tests/src/Common_Table_Operations/Add_Group_Number_Spec.enso

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ add_group_number_specs suite_builder setup =
7474
g7 = t.add_group_number (..Equal_Count 2 order_by='z') "g"
7575
g7.at 'g' . to_vector . should_equal [0, 1, 1, 0, 0]
7676

77+
g8 = t.add_group_number (..Equal_Count 1) "g"
78+
g8.at 'g' . to_vector . should_equal [0, 0, 0, 0, 0]
79+
80+
g9 = t.add_group_number (..Equal_Count 1 order_by=['x']) "g"
81+
g9.at 'g' . to_vector . should_equal [0, 0, 0, 0, 0]
82+
83+
g10 = t.add_group_number (..Equal_Count 1 order_by=['y']) "g"
84+
g10.at 'g' . to_vector . should_equal [0, 0, 0, 0, 0]
85+
86+
7787
group_builder.specify "should add group number by unique values" <|
7888
t = table_builder_from_rows ['x', 'y', 'z'] [[1, 0, 2], [0, 1, 0], [1, 2, 0], [0, 1, 1], [1, 0, 1], [1, 2, 1]]
7989

@@ -97,6 +107,16 @@ add_group_number_specs suite_builder setup =
97107

98108
t.add_group_number ..Unique "g" . should_fail_with Missing_Argument
99109

110+
group_builder.specify "must specify nonempty group_by with Unique" <|
111+
t = table_builder_from_rows ['x', 'y', 'z'] [[1, 0, 2], [0, 1, 0], [1, 2, 0], [0, 1, 1], [1, 0, 1], [1, 2, 1]]
112+
113+
t.add_group_number (..Unique on=[]) "g" . should_fail_with Illegal_Argument
114+
115+
group_builder.specify "must specify one or more groups with Equal_Count" <|
116+
t = table_builder [['x', [1, 2, 3, 4, 5]], ['y', [5, 4, 3, 2, 1]], ['z', [1, 5, 4, 2, 3]]]
117+
t.add_group_number (..Equal_Count 0) "g" . should_fail_with Illegal_Argument
118+
t.add_group_number (..Equal_Count -1) "g" . should_fail_with Illegal_Argument
119+
100120
group_builder.specify "should report floating point equality warning when grouping on float columns" <|
101121
t = table_builder_from_rows ['x', 'y', 'z'] [[1.0, 0.0, 2.0], [0.0, 1.0, 0.0], [1.0, 2.0, 0.0], [0.0, 1.0, 1.0], [1.0, 0.0, 1.0], [1.0, 2.0, 1.0]]
102122
g0 = t.add_group_number (..Unique on=['x', 'y']) "g"
@@ -124,8 +144,9 @@ add_group_number_specs suite_builder setup =
124144
t2.catch.to_display_text . should_contain "The row number has exceeded the 64-bit integer range"
125145

126146
group_builder.specify "should rename existing column upon a name clash, and attach a warning" <|
127-
t = table_builder_from_rows ['x', 'y', 'z'] [[1, 0, 2], [0, 1, 0], [1, 2, 0], [0, 1, 1], [1, 0, 1], [1, 2, 1]]
147+
t = table_builder_from_rows ['x', 'y', 'z'] [['b', 'a', 'c'], ['a', 'b', 'a'], ['b', 'b', 'a'], ['a', 'b', 'b'], ['b', 'a', 'b'], ['b', 'b', 'b']]
128148

129149
g0 = t.add_group_number (..Unique on=['x', 'y']) "y"
130-
g0.at 'y 1' . to_vector . should_equal [0, 1, 2, 1, 0, 2]
150+
g0.at 'y' . to_vector . should_equal [0, 1, 2, 1, 0, 2]
151+
g0.at 'y 1' . to_vector . should_equal ['a', 'b', 'b', 'b', 'a', 'b']
131152
Problems.expect_warning Duplicate_Output_Column_Names g0

0 commit comments

Comments
 (0)