Skip to content

Commit c7a8cc2

Browse files
committed
Build latest version for node and browser env
1 parent 8b8f32b commit c7a8cc2

3 files changed

Lines changed: 13 additions & 25 deletions

File tree

danfojs-browser/lib/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

danfojs-browser/lib/bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

danfojs-node/dist/core/series.js

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,19 @@ class Series extends _generic.default {
7373
}
7474
}
7575

76-
sample(num = 5) {
77-
if (num > this.values.length || num < 1) {
78-
let config = {
79-
columns: this.column_names
80-
};
81-
return new Series(this.values, config);
82-
} else {
83-
let values = this.values;
84-
let idx = this.index;
85-
let new_values = [];
86-
let new_idx = [];
87-
88-
let rand_nums = utils.__shuffle(num, idx);
76+
async sample(num = 5, seed = 1) {
77+
if (num > this.shape[0]) {
78+
throw new Error("Sample size n cannot be bigger than size of dataset");
79+
}
8980

90-
rand_nums.forEach(i => {
91-
new_values.push(values[i]);
92-
new_idx.push(idx[i]);
93-
});
94-
let config = {
95-
columns: this.column_names,
96-
index: new_idx
97-
};
98-
let sf = new Series(new_values, config);
99-
return sf;
81+
if (num < -1 || num == 0) {
82+
throw new Error("Sample size cannot be less than -1 or 0");
10083
}
84+
85+
num = num === -1 ? this.shape[0] : num;
86+
const shuffled_index = await tf.data.array(this.index).shuffle(num, seed).take(num).toArray();
87+
const sf = this.iloc(shuffled_index);
88+
return sf;
10189
}
10290

10391
add(other) {

0 commit comments

Comments
 (0)