Skip to content

Commit 8479d9a

Browse files
authored
Update grouping.md (#113)
* Update grouping.md * Update stats.jl * Update util.jl
1 parent ce57adf commit 8479d9a

File tree

3 files changed

+50
-20
lines changed

3 files changed

+50
-20
lines changed

docs/src/man/grouping.md

+15
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,21 @@ julia> groupby(salary, 2)
155155
10 2
156156
3 3
157157
5 3
158+
159+
julia> ds = Dataset(x=[1,1,2,2], y=[1,2,1,2], z=[1,1,1,1])
160+
161+
julia> groupby!(ds, [:x, :y]) # groupby by more than one column
162+
4×3 Grouped Dataset with 4 groups
163+
Grouped by: x, y
164+
Row │ x y z
165+
│ identity identity identity
166+
│ Int64? Int64? Int64?
167+
─────┼──────────────────────────────
168+
1 │ 1 1 1
169+
2 │ 1 2 1
170+
3 │ 2 1 1
171+
4 │ 2 2 1
172+
158173
```
159174

160175
The `groupby!` and `groupby` functions accept the output of the `groupby` function. Thus, some may use these functions to incrementally group a data set.

src/byrow/util.jl

+17-3
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ function _writeshortest(buf, pos, x::T,
428428
end
429429
i = 0
430430
ptr = pointer(buf)
431-
ptr2 = pointer(Base.Ryu.DIGIT_TABLE)
431+
ptr2 = pointer(our_DIGIT_TABLE)
432432
if (output >> 32) != 0
433433
q = output ÷ 100000000
434434
output2 = (output % UInt32) - UInt32(100000000) * (q % UInt32)
@@ -465,8 +465,8 @@ function _writeshortest(buf, pos, x::T,
465465
end
466466
if output2 >= 10
467467
c = output2 << 1
468-
buf[pos + 1] = Base.Ryu.DIGIT_TABLE[c + 2]
469-
buf[pos - exp_form] = Base.Ryu.DIGIT_TABLE[c + 1]
468+
buf[pos + 1] = our_DIGIT_TABLE[c + 2]
469+
buf[pos - exp_form] = our_DIGIT_TABLE[c + 1]
470470
else
471471
buf[pos - exp_form] = UInt8('0') + (output2 % UInt8)
472472
end
@@ -570,3 +570,17 @@ function _writeshortest(buf, pos, x::T,
570570

571571
return pos
572572
end
573+
574+
# FIXME in versions > 1.11 julia has change DIGIT_TABLE, we nee to update this for our purpose
575+
const our_DIGIT_TABLE = UInt8[
576+
'0','0','0','1','0','2','0','3','0','4','0','5','0','6','0','7','0','8','0','9',
577+
'1','0','1','1','1','2','1','3','1','4','1','5','1','6','1','7','1','8','1','9',
578+
'2','0','2','1','2','2','2','3','2','4','2','5','2','6','2','7','2','8','2','9',
579+
'3','0','3','1','3','2','3','3','3','4','3','5','3','6','3','7','3','8','3','9',
580+
'4','0','4','1','4','2','4','3','4','4','4','5','4','6','4','7','4','8','4','9',
581+
'5','0','5','1','5','2','5','3','5','4','5','5','5','6','5','7','5','8','5','9',
582+
'6','0','6','1','6','2','6','3','6','4','6','5','6','6','6','7','6','8','6','9',
583+
'7','0','7','1','7','2','7','3','7','4','7','5','7','6','7','7','7','8','7','9',
584+
'8','0','8','1','8','2','8','3','8','4','8','5','8','6','8','7','8','8','8','9',
585+
'9','0','9','1','9','2','9','3','9','4','9','5','9','6','9','7','9','8','9','9'
586+
]

test/stats.jl

+18-17
Original file line numberDiff line numberDiff line change
@@ -193,26 +193,27 @@ end
193193
x[50] = missing
194194
@test IMD.sum(y->ismissing(y) ? 0 : y, x) == sum(y->ismissing(y) ? 0 : y, x)
195195
end
196+
if VERSION > v"1.8" # it causes problem in v"1.6", however, we can ignore it for those versions
197+
x = rand(10)
198+
n_a = [@allocated IMD.sum(x) for _ in 1:10]
199+
@test n_a[end] <= 16
196200

197-
x = rand(10)
198-
n_a = [@allocated IMD.sum(x) for _ in 1:10]
199-
@test n_a[end] <= 16
201+
x = Union{Int32, Missing}[1,2,missing, 4]
202+
n_a = [@allocated IMD.sum(x) for _ in 1:10]
203+
@test n_a[end] == 0
200204

201-
x = Union{Int32, Missing}[1,2,missing, 4]
202-
n_a = [@allocated IMD.sum(x) for _ in 1:10]
203-
@test n_a[end] == 0
205+
n_a = [@allocated IMD.sum(y->ismissing(y) ? 0 : y, x) for _ in 1:10]
206+
@test n_a[end] <= 16
204207

205-
n_a = [@allocated IMD.sum(y->ismissing(y) ? 0 : y, x) for _ in 1:10]
206-
@test n_a[end] <= 16
208+
x = rand(10)
209+
n_a = [@allocated IMD.mean(x) for _ in 1:10]
210+
@test n_a[end] <= 16
207211

208-
x = rand(10)
209-
n_a = [@allocated IMD.mean(x) for _ in 1:10]
210-
@test n_a[end] <= 16
212+
x = Union{Int32, Missing}[1,2,missing, 4]
213+
n_a = [@allocated IMD.mean(x) for _ in 1:10]
214+
@test n_a[end] <= 16
211215

212-
x = Union{Int32, Missing}[1,2,missing, 4]
213-
n_a = [@allocated IMD.mean(x) for _ in 1:10]
214-
@test n_a[end] <= 16
215-
216-
n_a = [@allocated IMD.mean(y->ismissing(y) ? 0 : y, x) for _ in 1:10]
217-
@test n_a[end] <= 16
216+
n_a = [@allocated IMD.mean(y->ismissing(y) ? 0 : y, x) for _ in 1:10]
217+
@test n_a[end] <= 16
218+
end
218219
end

0 commit comments

Comments
 (0)