Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the viewhint option in Sample #238

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/transforms/sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ the same order of the original table.
# Examples

```julia
Sample(1_000)
Sample(1_000, replace=false)
Sample(1_000, replace=false, ordered=true)
Sample(1000)
Sample(1000, replace=false)
Sample(1000, replace=false, ordered=true)

# with rng
using Random
rng = MersenneTwister(2)
Sample(1_000, rng=rng)
Sample(1000, rng=rng)

# with weights
Sample(10, rand(100))
Expand Down Expand Up @@ -68,8 +68,8 @@ function applyfeat(::Sample, feat, prep)
sinds, rinds = prep

# selected and removed rows
srows = Tables.subset(feat, sinds)
rrows = Tables.subset(feat, rinds)
srows = Tables.subset(feat, sinds, viewhint=true)
rrows = Tables.subset(feat, rinds, viewhint=true)

newfeat = srows |> Tables.materializer(feat)
newfeat, (sinds, rinds, rrows)
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/satisfies.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Selects the columns that don't have scientific type `S`.

```julia
import DataScienceTraits as DST
Except(DST.Continuous)
Except(DST.Categorical)
```
"""
Except(S::Type{<:SciType}) = Satisfies(x -> !(elscitype(x) <: S))
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
CoDa = "5900dafe-f573-5c72-b367-76665857777b"
ColumnSelectors = "9cc86067-7e36-4c61-b350-1ac9833d277f"
DataScienceTraits = "6cb2f572-2d2b-4ba6-bdb3-e710fa044d6c"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using TableTransforms
using CoDa
using Tables
using Unitful
using TypedTables
Expand Down
9 changes: 9 additions & 0 deletions test/transforms/sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,13 @@
@test isapprox(count(==(trows[4]), nrows) / 10_000, 4 / 21, atol=0.01)
@test isapprox(count(==(trows[5]), nrows) / 10_000, 5 / 21, atol=0.01)
@test isapprox(count(==(trows[6]), nrows) / 10_000, 6 / 21, atol=0.01)

# performance tests
x = rand(100_000)
y = rand(100_000)
c = CoDaArray((a = rand(100_000), b = rand(100_000), c = rand(100_000)))
t = Table(; x, y, c)

T = Sample(10_000)
@test @elapsed(apply(T, t)) < 0.5
end
Loading