diff --git a/Project.toml b/Project.toml index b3bb15779..646131995 100644 --- a/Project.toml +++ b/Project.toml @@ -45,6 +45,7 @@ Reexport = "1" SentinelArrays = "1.2" ShiftedArrays = "1, 2" SortingAlgorithms = "0.3, 1" +StableRNGs = "1" Statistics = "1" TableTraits = "0.4, 1" Tables = "1.9.0" @@ -60,8 +61,21 @@ Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" ShiftedArrays = "1277b4bf-5013-50f5-be3d-901d8477a67a" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" +StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [targets] -test = ["CategoricalArrays", "Combinatorics", "DataValues", "Dates", "Logging", "OffsetArrays", "Test", "Unitful", "ShiftedArrays", "SparseArrays"] +test = [ + "CategoricalArrays", + "Combinatorics", + "DataValues", + "Dates", + "Logging", + "OffsetArrays", + "ShiftedArrays", + "SparseArrays", + "StableRNGs", + "Test", + "Unitful", +] diff --git a/docs/Project.toml b/docs/Project.toml index d821a4f08..ad8350455 100755 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -3,13 +3,16 @@ CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597" Chain = "8be319e6-bccf-4806-a6f7-6fae938471bc" DataFrameMacros = "75880514-38bc-4a95-a458-c2aea5a3a702" +DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" DataFramesMeta = "1313f7d8-7da2-5740-9ea0-a2ca25f37964" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" Missings = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" Query = "1a8c2f83-1ff3-5112-b086-8aa67b057ba1" +StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" TidierData = "fe2206b3-d496-4ee9-a338-6a095c4ece80" [compat] Documenter = "1" +StableRNGs = "1" diff --git a/docs/make.jl b/docs/make.jl index a5d5a4f4e..c590c7b7e 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,6 +1,7 @@ using Documenter using DataFrames using CategoricalArrays +using StableRNGs DocMeta.setdocmeta!(DataFrames, :DocTestSetup, :(using DataFrames); recursive=true) diff --git a/src/abstractdataframe/abstractdataframe.jl b/src/abstractdataframe/abstractdataframe.jl index bcf70a9f4..4fc42e453 100644 --- a/src/abstractdataframe/abstractdataframe.jl +++ b/src/abstractdataframe/abstractdataframe.jl @@ -2547,9 +2547,9 @@ $METADATA_FIXED # Examples ```jldoctest -julia> using Random +julia> using Random, StableRNGs -julia> rng = MersenneTwister(1234); +julia> rng = StableRNG(1234); julia> shuffle(rng, DataFrame(a=1:5, b=1:5)) 5×2 DataFrame @@ -2558,9 +2558,9 @@ julia> shuffle(rng, DataFrame(a=1:5, b=1:5)) ─────┼────────────── 1 │ 2 2 2 │ 1 1 - 3 │ 4 4 - 4 │ 3 3 - 5 │ 5 5 + 3 │ 3 3 + 4 │ 5 5 + 5 │ 4 4 ``` """ Random.shuffle(df::AbstractDataFrame) = @@ -2585,9 +2585,9 @@ Metadata having other styles is dropped (from parent data frame when `df` is a ` # Examples ```jldoctest -julia> using Random +julia> using Random, StableRNGs -julia> rng = MersenneTwister(1234); +julia> rng = StableRNG(1234); julia> shuffle!(rng, DataFrame(a=1:5, b=1:5)) 5×2 DataFrame @@ -2596,9 +2596,9 @@ julia> shuffle!(rng, DataFrame(a=1:5, b=1:5)) ─────┼────────────── 1 │ 2 2 2 │ 1 1 - 3 │ 4 4 - 4 │ 3 3 - 5 │ 5 5 + 3 │ 3 3 + 4 │ 5 5 + 5 │ 4 4 ``` """ Random.shuffle!(df::AbstractDataFrame) = diff --git a/test/dataframe.jl b/test/dataframe.jl index 940590852..74fa10784 100644 --- a/test/dataframe.jl +++ b/test/dataframe.jl @@ -1,7 +1,7 @@ module TestDataFrame using Dates, DataFrames, Statistics, Random, Test, Logging, DataStructures, - CategoricalArrays + CategoricalArrays, StableRNGs using DataFrames: _columns, index using OffsetArrays: OffsetArray const ≅ = isequal @@ -2136,8 +2136,8 @@ end refdf = DataFrame(a=1:5, b=11:15) refdf.c = refdf.a for df in (refdf, view(refdf, 2:5, [2, 1])) - x = randperm(MersenneTwister(1234), nrow(df)) - mt = MersenneTwister(1234) + x = randperm(StableRNG(1234), nrow(df)) + mt = StableRNG(1234) @test shuffle(mt, df) == df[x, :] Random.seed!(1234) x = randperm(nrow(df)) @@ -2145,8 +2145,8 @@ end @test shuffle(df) == df[x, :] end df = copy(refdf) - x = randperm(MersenneTwister(1234), nrow(df)) - mt = MersenneTwister(1234) + x = randperm(StableRNG(1234), nrow(df)) + mt = StableRNG(1234) @test shuffle!(mt, df) === df @test df == refdf[x, :] df = copy(refdf) @@ -2158,8 +2158,8 @@ end df = copy(refdf) dfv = view(df, 2:4, [3, 1]) - x = randperm(MersenneTwister(1234), nrow(dfv)) - mt = MersenneTwister(1234) + x = randperm(StableRNG(1234), nrow(dfv)) + mt = StableRNG(1234) @test shuffle!(mt, dfv) === dfv @test dfv == view(refdf, 2:4, [3, 1])[x, :] @test df[1, :] == refdf[1, :]