Skip to content

Commit 5285e4f

Browse files
authored
Merge pull request #208 from opensource9ja/fix/object-testing
Fixes #206 Testing if value is an object
2 parents dc6c217 + c4b80ff commit 5285e4f

File tree

12 files changed

+219
-407
lines changed

12 files changed

+219
-407
lines changed

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.LICENSE.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,23 @@
163163
* =============================================================================
164164
*/
165165

166+
/**
167+
* @license
168+
* Copyright 2021 Google LLC. All Rights Reserved.
169+
* Licensed under the Apache License, Version 2.0 (the "License");
170+
* you may not use this file except in compliance with the License.
171+
* You may obtain a copy of the License at
172+
*
173+
* https://www.apache.org/licenses/LICENSE-2.0
174+
*
175+
* Unless required by applicable law or agreed to in writing, software
176+
* distributed under the License is distributed on an "AS IS" BASIS,
177+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
178+
* See the License for the specific language governing permissions and
179+
* limitations under the License.
180+
* =============================================================================
181+
*/
182+
166183
/**
167184
* @license Complex.js v2.0.11 11/02/2016
168185
*

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-browser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"types"
2222
],
2323
"dependencies": {
24-
"@tensorflow/tfjs": "3.3.0",
24+
"@tensorflow/tfjs": "3.6.0",
2525
"mathjs": "7.5.1",
2626
"table": "^5.4.6",
2727
"xlsx": "^0.16.7"

danfojs-browser/src/core/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class Utils {
3434

3535
// Returns if a value is an object
3636
__is_object(value) {
37-
return value && typeof value === "object" && value.constructor === Object;
37+
return value && typeof value === "object" && value.constructor && value.constructor.name === "Object";
3838
}
3939

4040
// Returns if a value is null

danfojs-browser/yarn.lock

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -894,66 +894,66 @@
894894
readdirp "^2.2.1"
895895
upath "^1.1.1"
896896

897-
"@tensorflow/tfjs-backend-cpu@3.3.0":
898-
version "3.3.0"
899-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-cpu/-/tfjs-backend-cpu-3.3.0.tgz#aa0a3ed2c6237a6e0c169678c5bd4b5a88766b1c"
900-
integrity sha512-DLctv+PUZni26kQW1hq8jwQQ8u+GGc/p764WQIC4/IDagGtfGAUW1mHzWcTxtni2l4re1VrwE41ogWLhv4sGHg==
897+
"@tensorflow/tfjs-backend-cpu@3.6.0":
898+
version "3.6.0"
899+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-cpu/-/tfjs-backend-cpu-3.6.0.tgz#4e64a7cf1c33b203f71f8f77cd7b0ac1ef25a871"
900+
integrity sha512-ZpAs17hPdKXadbtNjAsymYUILe8V7+pY4fYo8j25nfDTW/HfBpyAwsHPbMcA/n5zyJ7ZJtGKFcCUv1sl24KL1Q==
901901
dependencies:
902902
"@types/seedrandom" "2.4.27"
903903
seedrandom "2.4.3"
904904

905-
"@tensorflow/tfjs-backend-webgl@3.3.0":
906-
version "3.3.0"
907-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-webgl/-/tfjs-backend-webgl-3.3.0.tgz#29dd665f6a856c9defcb9108164f845e1fdcd02e"
908-
integrity sha512-GWCtXbrjPTyye3ooId9GlcNDwnIMskZarUpNIQ5g/zeISLfwEQoutA/UqJF+HzuEHgGMsWFkmaO3xKVT7UMpdg==
905+
"@tensorflow/tfjs-backend-webgl@3.6.0":
906+
version "3.6.0"
907+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-webgl/-/tfjs-backend-webgl-3.6.0.tgz#1ea1a73abea8d6324fd81aedf7f187ab6eb73692"
908+
integrity sha512-zp7l4TmD1khgeSux/Ujaaj8M/v+e8JVIKjOci6HCGaeMNrn74lTSH9oqGPWKUCmpZME17/V0LfRHK34ddmrPSA==
909909
dependencies:
910-
"@tensorflow/tfjs-backend-cpu" "3.3.0"
910+
"@tensorflow/tfjs-backend-cpu" "3.6.0"
911911
"@types/offscreencanvas" "~2019.3.0"
912912
"@types/seedrandom" "2.4.27"
913913
"@types/webgl-ext" "0.0.30"
914914
"@types/webgl2" "0.0.5"
915915
seedrandom "2.4.3"
916916

917-
"@tensorflow/tfjs-converter@3.3.0":
918-
version "3.3.0"
919-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-converter/-/tfjs-converter-3.3.0.tgz#d9f2ffd0fbdbb47c07d5fd7c3e5dc180cff317aa"
920-
integrity sha512-k57wN4yelePhmO9orcT/wzGMIuyedrMpVtg0FhxpV6BQu0+TZ/ti3W4Kb97GWJsoHKXMoing9SnioKfVnBW6hw==
917+
"@tensorflow/tfjs-converter@3.6.0":
918+
version "3.6.0"
919+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-converter/-/tfjs-converter-3.6.0.tgz#32b3ff31b47e29630a82e30fbe01708facad7fd6"
920+
integrity sha512-9MtatbTSvo3gpEulYI6+byTA3OeXSMT2lzyGAegXO9nMxsvjR01zBvlZ5SmsNyecNh6fMSzdL2+cCdQfQtsIBg==
921921

922-
"@tensorflow/tfjs-core@3.3.0":
923-
version "3.3.0"
924-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-core/-/tfjs-core-3.3.0.tgz#3d26bd03cb58e0ecf46c96d118c39c4a90b7f5ed"
925-
integrity sha512-6G+LcCiQBl4Kza5mDbWbf8QSWBTW3l7SDjGhQzMO1ITtQatHzxkuHGHcJ4CTUJvNA0JmKf4QJWOvlFqEmxwyLQ==
922+
"@tensorflow/tfjs-core@3.6.0":
923+
version "3.6.0"
924+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-core/-/tfjs-core-3.6.0.tgz#6b4d8175790bdff78868eabe6adc6442eb4dc276"
925+
integrity sha512-bb2c3zwK4SgXZRvkTiC7EhCpWbCGp0GMd+1/3Vo2/Z54jiLB/h3sXIgHQrTNiWwhKPtst/xxA+MsslFlvD0A5w==
926926
dependencies:
927927
"@types/offscreencanvas" "~2019.3.0"
928928
"@types/seedrandom" "2.4.27"
929929
"@types/webgl-ext" "0.0.30"
930930
node-fetch "~2.6.1"
931931
seedrandom "2.4.3"
932932

933-
"@tensorflow/tfjs-data@3.3.0":
934-
version "3.3.0"
935-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-data/-/tfjs-data-3.3.0.tgz#ba943bd6a486fa4cb3ca312c12646ea4dcf6cce4"
936-
integrity sha512-0x28tRe6RJu5GmYq3IYN2GNnOgXU0nY+o6zZrlijkK+W3vjSTJlZzaBSifoeD6J8gzVpjs8W8qd/JKHQ1MQp8w==
933+
"@tensorflow/tfjs-data@3.6.0":
934+
version "3.6.0"
935+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-data/-/tfjs-data-3.6.0.tgz#af2f03cffb75ad8e4c2f46e192e392d9b7f977ed"
936+
integrity sha512-5KU7fnU7cj/opb4aCNDoW4qma64ggDwI0PCs5KEO41T3waVHDLk6bjlFlBVRdjfZqvM0K6EfWEyoiXzdvz/Ieg==
937937
dependencies:
938938
"@types/node-fetch" "^2.1.2"
939939
node-fetch "~2.6.1"
940940

941-
"@tensorflow/tfjs-layers@3.3.0":
942-
version "3.3.0"
943-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-layers/-/tfjs-layers-3.3.0.tgz#d2097c5b22ec12e5fdbe470a88ca0a34a95ca11f"
944-
integrity sha512-qO+TL2I29vWUiuFcQJXNyayWFYagwR+SIfbex8p5jjYaCGHGwE5GQcrH+ngoCgKZxm5tdMvYJsJPnih2M3fYzQ==
941+
"@tensorflow/tfjs-layers@3.6.0":
942+
version "3.6.0"
943+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-layers/-/tfjs-layers-3.6.0.tgz#5358af559fc8baed304b3e567319fe93f1aa46a6"
944+
integrity sha512-B7EHwAT6KFqhKzdf0e2Sr6haj9qpqpyEATV8OCPHdk+g8z2AGXOLlFfbgW6vCMjy1wb5jzYqCyZDoY3EWdgJAw==
945945

946-
"@tensorflow/tfjs@3.3.0":
947-
version "3.3.0"
948-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs/-/tfjs-3.3.0.tgz#db92099dd48c0eb1c1673f705125d2b57496a1a3"
949-
integrity sha512-xo22GCUCGcPtNGIdDpLPrp9ms3atXmzX8AF4y3aIBEwK5KlvGe+ZhcoQ2xEOCPQGBr7NB7AO6rwT8gRoziAHVg==
950-
dependencies:
951-
"@tensorflow/tfjs-backend-cpu" "3.3.0"
952-
"@tensorflow/tfjs-backend-webgl" "3.3.0"
953-
"@tensorflow/tfjs-converter" "3.3.0"
954-
"@tensorflow/tfjs-core" "3.3.0"
955-
"@tensorflow/tfjs-data" "3.3.0"
956-
"@tensorflow/tfjs-layers" "3.3.0"
946+
"@tensorflow/tfjs@3.6.0":
947+
version "3.6.0"
948+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs/-/tfjs-3.6.0.tgz#e65956cd40c96523e3f5ec7a58a4bef9ef5e349c"
949+
integrity sha512-uLDMDzyRkJa3fYBeR6etQTFD/t+nkQIH/DznL9hxmYoIYG8PigY2gcrc482TAvsdhiuvxCZ9rl5SyDtP93MvxQ==
950+
dependencies:
951+
"@tensorflow/tfjs-backend-cpu" "3.6.0"
952+
"@tensorflow/tfjs-backend-webgl" "3.6.0"
953+
"@tensorflow/tfjs-converter" "3.6.0"
954+
"@tensorflow/tfjs-core" "3.6.0"
955+
"@tensorflow/tfjs-data" "3.6.0"
956+
"@tensorflow/tfjs-layers" "3.6.0"
957957
argparse "^1.0.10"
958958
chalk "^4.1.0"
959959
core-js "3"

danfojs-node/dist/core/frame.js

Lines changed: 23 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -924,74 +924,34 @@ class DataFrame extends _generic.default {
924924
}
925925

926926
groupby(col) {
927-
let len = this.shape[0];
928-
let column_names = this.column_names;
929-
let col_dict = {};
930-
let key_column = null;
931-
let col_index = col.map(val => column_names.indexOf(val));
932-
let col_dtype = this.dtypes.filter((val, index) => {
927+
const len = this.shape[0];
928+
const column_names = this.column_names;
929+
const col_index = col.map(val => column_names.indexOf(val));
930+
const col_dtype = this.dtypes.filter((val, index) => {
933931
return col_index.includes(index);
934932
});
933+
const self = this;
934+
const data = col.map(column_name => {
935+
if (!column_names.includes(column_name)) throw new Error(`column ${column_name} does not exist`);
936+
const [column_data, _] = (0, _indexing.indexLoc)(self, {
937+
rows: [`0:${len}`],
938+
columns: [`${column_name}`],
939+
type: "loc"
940+
});
941+
return column_data;
942+
});
943+
const unique_columns = data.map(column_data => utils.__unique(column_data));
935944

936-
if (col.length == 2) {
937-
if (column_names.includes(col[0])) {
938-
var [data1, col_name1] = (0, _indexing.indexLoc)(this, {
939-
rows: [`0:${len}`],
940-
columns: [`${col[0]}`],
941-
type: "loc"
942-
});
943-
} else {
944-
throw new Error(`column ${col[0]} does not exist`);
945-
}
946-
947-
if (column_names.includes(col[1])) {
948-
var [data2, col_name2] = (0, _indexing.indexLoc)(this, {
949-
rows: [`0:${len}`],
950-
columns: [`${col[1]}`],
951-
type: "loc"
952-
});
953-
} else {
954-
throw new Error(`column ${col[1]} does not exist`);
955-
}
956-
957-
key_column = [col[0], col[1]];
958-
959-
var column_1_Unique = utils.__unique(data1);
960-
961-
var column_2_unique = utils.__unique(data2);
962-
963-
for (var i = 0; i < column_1_Unique.length; i++) {
964-
let col_value = column_1_Unique[i];
965-
col_dict[col_value] = {};
966-
967-
for (var j = 0; j < column_2_unique.length; j++) {
968-
let col2_value = column_2_unique[j];
969-
col_dict[col_value][col2_value] = [];
970-
}
971-
}
972-
} else {
973-
if (column_names.includes(col[0])) {
974-
var [data1, col_name1] = (0, _indexing.indexLoc)(this, {
975-
rows: [`0:${len}`],
976-
columns: [`${col[0]}`],
977-
type: "loc"
978-
});
979-
} else {
980-
throw new Error(`column ${col[0]} does not exist`);
981-
}
982-
983-
key_column = [col[0]];
984-
985-
var column_Unique = utils.__unique(data1);
986-
987-
for (let i = 0; i < column_Unique.length; i++) {
988-
let col_value = column_Unique[i];
989-
col_dict[col_value] = [];
990-
}
945+
function getRecursiveDict(uniq_columns) {
946+
const first_uniq_columns = uniq_columns[0];
947+
const remaining_columns = uniq_columns.slice(1);
948+
const c_dict = {};
949+
if (!remaining_columns.length) first_uniq_columns.forEach(col_value => c_dict[col_value] = []);else first_uniq_columns.forEach(col_value => c_dict[col_value] = getRecursiveDict(remaining_columns));
950+
return c_dict;
991951
}
992952

993-
let groups = new _groupby.GroupBy(col_dict, key_column, this.values, column_names, col_dtype).group();
994-
return groups;
953+
const col_dict = getRecursiveDict(unique_columns);
954+
return new _groupby.GroupBy(col_dict, col, this.values, column_names, col_dtype).group();
995955
}
996956

997957
column(col_name) {

0 commit comments

Comments
 (0)