sample doesnt work as expected
Describe the bug seems like 2 issues:
- sample should return changing sets if no seed provided
- sample should return sets encompassing the entire set of rows, unrelated to the number of items requested. Both of these appear to not be satisfied.
To Reproduce Steps to reproduce the behavior: ` import * as danfo from 'danfojs-node';
async function load_data() { const data = [{ 'Index': 1, 'Foo': 'foo' }, { 'Index': 2, 'Foo': 'foo' }, { 'Index': 3, 'Foo': 'foo' }, { 'Index': 4, 'Foo': 'foo' }, { 'Index': 5, 'Foo': 'foo' }, { 'Index': 6, 'Foo': 'foo' }, { 'Index': 7, 'Foo': 'foo' }, { 'Index': 8, 'Foo': 'foo' }, { 'Index': 9, 'Foo': 'foo' }, { 'Index': 10, 'Foo': 'foo' }, { 'Index': 11, 'Foo': 'foo' }, { 'Index': 12, 'Foo': 'foo' }, { 'Index': 13, 'Foo': 'foo' }, { 'Index': 14, 'Foo': 'foo' }, { 'Index': 15, 'Foo': 'foo' }, { 'Index': 16, 'Foo': 'foo' }, { 'Index': 17, 'Foo': 'foo' }, { 'Index': 18, 'Foo': 'foo' }, { 'Index': 19, 'Foo': 'foo' }, { 'Index': 20, 'Foo': 'foo' }, { 'Index': 21, 'Foo': 'foo' }, { 'Index': 22, 'Foo': 'foo' }, { 'Index': 23, 'Foo': 'foo' }, { 'Index': 24, 'Foo': 'foo' }, { 'Index': 25, 'Foo': 'foo' }, { 'Index': 26, 'Foo': 'foo' }, { 'Index': 27, 'Foo': 'foo' }, { 'Index': 28, 'Foo': 'foo' }, { 'Index': 29, 'Foo': 'foo' }, { 'Index': 30, 'Foo': 'foo' }, { 'Index': 31, 'Foo': 'foo' }, { 'Index': 32, 'Foo': 'foo' }, { 'Index': 33, 'Foo': 'foo' }, { 'Index': 34, 'Foo': 'foo' }, { 'Index': 35, 'Foo': 'foo' }, { 'Index': 36, 'Foo': 'foo' }, { 'Index': 37, 'Foo': 'foo' }, { 'Index': 38, 'Foo': 'foo' }, { 'Index': 39, 'Foo': 'foo' }, { 'Index': 40, 'Foo': 'foo' }, { 'Index': 41, 'Foo': 'foo' }, { 'Index': 42, 'Foo': 'foo' }, { 'Index': 43, 'Foo': 'foo' }, { 'Index': 44, 'Foo': 'foo' }, { 'Index': 45, 'Foo': 'foo' }, { 'Index': 46, 'Foo': 'foo' }, { 'Index': 47, 'Foo': 'foo' }, { 'Index': 48, 'Foo': 'foo' }, { 'Index': 49, 'Foo': 'foo' }, { 'Index': 50, 'Foo': 'foo' }, { 'Index': 51, 'Foo': 'foo' }, { 'Index': 52, 'Foo': 'foo' }, { 'Index': 53, 'Foo': 'foo' }, { 'Index': 54, 'Foo': 'foo' }, { 'Index': 55, 'Foo': 'foo' }, { 'Index': 56, 'Foo': 'foo' }, { 'Index': 57, 'Foo': 'foo' }, { 'Index': 58, 'Foo': 'foo' }, { 'Index': 59, 'Foo': 'foo' }, { 'Index': 60, 'Foo': 'foo' }, { 'Index': 61, 'Foo': 'foo' }, { 'Index': 62, 'Foo': 'foo' }, { 'Index': 63, 'Foo': 'foo' }, { 'Index': 64, 'Foo': 'foo' }, { 'Index': 65, 'Foo': 'foo' }, { 'Index': 66, 'Foo': 'foo' }, { 'Index': 67, 'Foo': 'foo' }, { 'Index': 68, 'Foo': 'foo' }, { 'Index': 69, 'Foo': 'foo' }, { 'Index': 70, 'Foo': 'foo' }, { 'Index': 71, 'Foo': 'foo' }, { 'Index': 72, 'Foo': 'foo' }, { 'Index': 73, 'Foo': 'foo' }, { 'Index': 74, 'Foo': 'foo' }, { 'Index': 75, 'Foo': 'foo' }, { 'Index': 76, 'Foo': 'foo' }, { 'Index': 77, 'Foo': 'foo' }, { 'Index': 78, 'Foo': 'foo' }, { 'Index': 79, 'Foo': 'foo' }, { 'Index': 80, 'Foo': 'foo' }, { 'Index': 81, 'Foo': 'foo' }, { 'Index': 82, 'Foo': 'foo' }, { 'Index': 83, 'Foo': 'foo' }, { 'Index': 84, 'Foo': 'foo' }, { 'Index': 85, 'Foo': 'foo' }, { 'Index': 86, 'Foo': 'foo' }, { 'Index': 87, 'Foo': 'foo' }, { 'Index': 88, 'Foo': 'foo' }, { 'Index': 89, 'Foo': 'foo' }, { 'Index': 90, 'Foo': 'foo' }, { 'Index': 91, 'Foo': 'foo' }, { 'Index': 92, 'Foo': 'foo' }, { 'Index': 93, 'Foo': 'foo' }, { 'Index': 94, 'Foo': 'foo' }, { 'Index': 95, 'Foo': 'foo' }, { 'Index': 96, 'Foo': 'foo' }, { 'Index': 97, 'Foo': 'foo' }, { 'Index': 98, 'Foo': 'foo' }, { 'Index': 99, 'Foo': 'foo' }, { 'Index': 100, 'Foo': 'foo' }]; const df = new danfo.DataFrame(data); for (let i = 0; i < 2; i++) { const s_df = await df.sample(5); s_df.print(); } } `
The output I get is: ` ╔════════════╤═══════════════════╤═══════════════════╗ ║ │ Index │ Foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 2 │ 3 │ foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 4 │ 5 │ foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 0 │ 1 │ foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 7 │ 8 │ foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 6 │ 7 │ foo ║ ╚════════════╧═══════════════════╧═══════════════════╝
╔════════════╤═══════════════════╤═══════════════════╗ ║ │ Index │ Foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 2 │ 3 │ foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 4 │ 5 │ foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 0 │ 1 │ foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 7 │ 8 │ foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 6 │ 7 │ foo ║ ╚════════════╧═══════════════════╧═══════════════════╝ `
Expected behavior The above code seems to break the 2 requirements...
- the random set is the same each time.
- the random set only contains index values with small numbers
Additionally, if you vary the size of the set requested, the range of returned indexes increases, ie for 10 results: ` ╔════════════╤═══════════════════╤═══════════════════╗ ║ │ Index │ Foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 4 │ 5 │ foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 5 │ 6 │ foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 0 │ 1 │ foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 8 │ 9 │ foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 1 │ 2 │ foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 3 │ 4 │ foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 11 │ 12 │ foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 13 │ 14 │ foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 2 │ 3 │ foo ║ ╟────────────┼───────────────────┼───────────────────╢ ║ 15 │ 16 │ foo ║ ╚════════════╧═══════════════════╧═══════════════════╝
` but does not come close to indexes near the full set of 100, and this is independent of seed.