Skip to content

Commit 709a2f5

Browse files
authored
Use the viewhint option in Sample (#238)
* Use the 'viewhint' option in 'Sample' * Update tests * Update tests
1 parent a5394d0 commit 709a2f5

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

src/transforms/sample.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ the same order of the original table.
1212
# Examples
1313
1414
```julia
15-
Sample(1_000)
16-
Sample(1_000, replace=false)
17-
Sample(1_000, replace=false, ordered=true)
15+
Sample(1000)
16+
Sample(1000, replace=false)
17+
Sample(1000, replace=false, ordered=true)
1818
1919
# with rng
2020
using Random
2121
rng = MersenneTwister(2)
22-
Sample(1_000, rng=rng)
22+
Sample(1000, rng=rng)
2323
2424
# with weights
2525
Sample(10, rand(100))
@@ -68,8 +68,8 @@ function applyfeat(::Sample, feat, prep)
6868
sinds, rinds = prep
6969

7070
# selected and removed rows
71-
srows = Tables.subset(feat, sinds)
72-
rrows = Tables.subset(feat, rinds)
71+
srows = Tables.subset(feat, sinds, viewhint=true)
72+
rrows = Tables.subset(feat, rinds, viewhint=true)
7373

7474
newfeat = srows |> Tables.materializer(feat)
7575
newfeat, (sinds, rinds, rrows)

src/transforms/satisfies.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Selects the columns that don't have scientific type `S`.
6262
6363
```julia
6464
import DataScienceTraits as DST
65-
Except(DST.Continuous)
65+
Except(DST.Categorical)
6666
```
6767
"""
6868
Except(S::Type{<:SciType}) = Satisfies(x -> !(elscitype(x) <: S))

test/Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[deps]
22
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
33
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
4+
CoDa = "5900dafe-f573-5c72-b367-76665857777b"
45
ColumnSelectors = "9cc86067-7e36-4c61-b350-1ac9833d277f"
56
DataScienceTraits = "6cb2f572-2d2b-4ba6-bdb3-e710fa044d6c"
67
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"

test/runtests.jl

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using TableTransforms
2+
using CoDa
23
using Tables
34
using Unitful
45
using TypedTables

test/transforms/sample.jl

+9
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,13 @@
6060
@test isapprox(count(==(trows[4]), nrows) / 10_000, 4 / 21, atol=0.01)
6161
@test isapprox(count(==(trows[5]), nrows) / 10_000, 5 / 21, atol=0.01)
6262
@test isapprox(count(==(trows[6]), nrows) / 10_000, 6 / 21, atol=0.01)
63+
64+
# performance tests
65+
x = rand(100_000)
66+
y = rand(100_000)
67+
c = CoDaArray((a = rand(100_000), b = rand(100_000), c = rand(100_000)))
68+
t = Table(; x, y, c)
69+
70+
T = Sample(10_000)
71+
@test @elapsed(apply(T, t)) < 0.5
6372
end

0 commit comments

Comments
 (0)