@@ -4,15 +4,19 @@ using StatsBase
4
4
using Random
5
5
6
6
a = rand (1 : 10000 , 1000 )
7
+ am = [rand () < .9 ? i : missing for i in a]
7
8
8
- for alg in [TimSort, HeapSort, RadixSort, CombSort]
9
+ for alg in [TimSort, HeapSort, RadixSort, CombSort, SortingAlgorithms . TimSortAlg () ]
9
10
b = sort (a, alg= alg)
10
11
@test issorted (b)
11
12
ix = sortperm (a, alg= alg)
12
13
b = a[ix]
13
14
@test issorted (b)
14
15
@test a[ix] == b
15
16
17
+ # legacy 3-argument calling convention
18
+ @test b == sort! (copy (a), alg, Base. Order. Forward)
19
+
16
20
b = sort (a, alg= alg, rev= true )
17
21
@test issorted (b, rev= true )
18
22
ix = sortperm (a, alg= alg, rev= true )
@@ -34,9 +38,26 @@ for alg in [TimSort, HeapSort, RadixSort, CombSort]
34
38
invpermute! (c, ix)
35
39
@test c == a
36
40
37
- if alg != RadixSort # RadixSort does not work with Lt orderings
41
+ if alg != RadixSort # RadixSort does not work with Lt orderings or missing
38
42
c = sort (a, alg= alg, lt= (> ))
39
43
@test b == c
44
+
45
+ # Issue https://github.com/JuliaData/DataFrames.jl/issues/3340
46
+ bm1 = sort (am, alg= alg)
47
+ @test issorted (bm1)
48
+ @test count (ismissing, bm1) == count (ismissing, am)
49
+
50
+ bm2 = am[sortperm (am, alg= alg)]
51
+ @test issorted (bm2)
52
+ @test count (ismissing, bm2) == count (ismissing, am)
53
+
54
+ bm3 = am[sortperm! (collect (eachindex (am)), am, alg= alg)]
55
+ @test issorted (bm3)
56
+ @test count (ismissing, bm3) == count (ismissing, am)
57
+
58
+ if alg == TimSort # Stable
59
+ @test all (bm1 .=== bm2 .=== bm3)
60
+ end
40
61
end
41
62
42
63
c = sort (a, alg= alg, by= x-> 1 / x)
@@ -103,8 +124,8 @@ for n in [0:10..., 100, 101, 1000, 1001]
103
124
# test float sorting with NaNs
104
125
s = sort (v, alg= alg, order= ord)
105
126
@test issorted (s, order= ord)
106
-
107
- # This tests that NaNs (which compare equivalent) are treated stably
127
+
128
+ # This tests that NaNs (which compare equivalent) are treated stably
108
129
# even when the underlying algorithm is unstable. That it happens to
109
130
# pass is not a part of the public API:
110
131
@test reinterpret (UInt64, v[map (isnan, v)]) == reinterpret (UInt64, s[map (isnan, s)])
0 commit comments