Skip to content

Commit 897705d

Browse files
authored
Merge pull request #320 from opensource9ja/misc/fixes
Misc/fixes
2 parents 61dc2f7 + 91c22b5 commit 897705d

File tree

10 files changed

+265
-210
lines changed

10 files changed

+265
-210
lines changed

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.9.0",
24+
"@tensorflow/tfjs": "3.11.0",
2525
"mathjs": "9.4.4",
2626
"papaparse": "^5.3.1",
2727
"request": "^2.88.2",

danfojs-browser/src/core/frame.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,8 +2043,10 @@ export default class DataFrame extends NDframe {
20432043
}
20442044

20452045
if (axis === 1) {
2046+
const colsAdded = [];
20462047
const newColumns = this.columns.map((col) => {
20472048
if (mapper[col] !== undefined) {
2049+
colsAdded.push(mapper[col]);
20482050
return mapper[col];
20492051
} else {
20502052
return col;
@@ -2053,6 +2055,9 @@ export default class DataFrame extends NDframe {
20532055

20542056
if (inplace) {
20552057
this.$setColumnNames(newColumns);
2058+
for (const col of colsAdded) {
2059+
this.$setInternalColumnDataProperty(col);
2060+
}
20562061
} else {
20572062
return new DataFrame([...this.values], {
20582063
index: [...this.index],
@@ -2287,6 +2292,7 @@ export default class DataFrame extends NDframe {
22872292
} else {
22882293
return new DataFrame(newData, {
22892294
index: newIndex,
2295+
columns: this.columns,
22902296
config: { ...this.config }
22912297
});
22922298
}

danfojs-browser/tests/core/frame.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,15 @@ describe("DataFrame", function () {
11391139

11401140
assert.deepEqual(newdf.dtypes, dtype);
11411141
});
1142+
it("Confirms that column names are not changed", function () {
1143+
1144+
let data = [[1, 2, 3], [4, 5, 6], [20, 30, 40], [39, 89, 78]];
1145+
let cols = ["A", "B", "C"];
1146+
let df = new dfd.DataFrame(data, { columns: cols });
1147+
let df_query = df.query({ "column": "B", "is": ">=", "to": 5 });
1148+
assert.deepEqual(df_query.index, [1, 2, 3]);
1149+
assert.deepEqual(df_query.columns, ["A", "B", "C"]);
1150+
});
11421151

11431152
});
11441153

@@ -2011,6 +2020,28 @@ describe("DataFrame", function () {
20112020
assert.deepEqual(df.index, res);
20122021

20132022
});
2023+
2024+
it("Get new column via subseting works after rename (inplace)", function () {
2025+
let data = {
2026+
"A": [-20, 30, 47.3],
2027+
"B": [34, -4, 5],
2028+
"C": [20, 2, 30]
2029+
};
2030+
let df = new dfd.DataFrame(data);
2031+
df.rename({ mapper: { "A": "new_name" }, inplace: true });
2032+
assert.deepEqual(df["new_name"].values, data["A"]);
2033+
});
2034+
2035+
it("Get new column via subseting works after rename (not-inplace)", function () {
2036+
let data = {
2037+
"A": [-20, 30, 47.3],
2038+
"B": [34, -4, 5],
2039+
"C": [20, 2, 30]
2040+
};
2041+
let df = new dfd.DataFrame(data);
2042+
let new_df = df.rename({ mapper: { "A": "new_name" } });
2043+
assert.deepEqual(new_df["new_name"].values, data["A"]);
2044+
});
20142045
});
20152046

20162047
describe("sort_index", function () {

danfojs-browser/types/core/frame.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,5 +551,5 @@ export class DataFrame extends NDframe implements DataFrameInterface {
551551
inplace?: boolean;
552552
}): DataFrame | void;
553553

554-
groupby(column: string): GroupBy;
554+
groupby(column: Array<string>): GroupBy;
555555
}

danfojs-browser/yarn.lock

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -901,35 +901,35 @@
901901
readdirp "^2.2.1"
902902
upath "^1.1.1"
903903

904-
"@tensorflow/tfjs-backend-cpu@3.9.0":
905-
version "3.9.0"
906-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-cpu/-/tfjs-backend-cpu-3.9.0.tgz#27ee581a4765039eb0e84d9d473b6d5f2769c813"
907-
integrity sha512-PUv5B3wdQsA8cysk+oUhA0NqMoo/lwP8EazC/axQc8/72Dc6kU8uw/5qZtE5P4xXSqkNSlh2ifFm+8nH/6B+iA==
904+
"@tensorflow/tfjs-backend-cpu@3.11.0":
905+
version "3.11.0"
906+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-cpu/-/tfjs-backend-cpu-3.11.0.tgz#01d5d68b91faf12bee4854adae56bc956b794f1a"
907+
integrity sha512-ShLkrZ4/rmhZwzGKenMFDfQnaEbyZgWA5F8JRa52Iob/vptlZeuOzjq87CZKmZMUmDswR9A2kjzovT/H1bJdWQ==
908908
dependencies:
909909
"@types/seedrandom" "2.4.27"
910910
seedrandom "2.4.3"
911911

912-
"@tensorflow/tfjs-backend-webgl@3.9.0":
913-
version "3.9.0"
914-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-webgl/-/tfjs-backend-webgl-3.9.0.tgz#103630e23d4325492bfbe2ff65b58c24ad852377"
915-
integrity sha512-oUnyQFF9aCnNZpul9AnJwrt8noDJdMmxgq2+e/0DpEMBERcywtVj9qkKCccMaVFsdQV1lQxpV3kjC3vbFMDWKg==
912+
"@tensorflow/tfjs-backend-webgl@3.11.0":
913+
version "3.11.0"
914+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-backend-webgl/-/tfjs-backend-webgl-3.11.0.tgz#fbd7f24c164d17c11d964206b4b075b073b1a3bc"
915+
integrity sha512-rNnc/dZ7LIl9O/Pn9W24I1h8kgpJ+XvG8NrdNSfIoWPCW4fvPSlU7B3yMeZXvRneny+z+T3xRs96nWyU2mZBJw==
916916
dependencies:
917-
"@tensorflow/tfjs-backend-cpu" "3.9.0"
917+
"@tensorflow/tfjs-backend-cpu" "3.11.0"
918918
"@types/offscreencanvas" "~2019.3.0"
919919
"@types/seedrandom" "2.4.27"
920920
"@types/webgl-ext" "0.0.30"
921-
"@types/webgl2" "0.0.5"
921+
"@types/webgl2" "0.0.6"
922922
seedrandom "2.4.3"
923923

924-
"@tensorflow/tfjs-converter@3.9.0":
925-
version "3.9.0"
926-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-converter/-/tfjs-converter-3.9.0.tgz#e00709002cbe04ff5cc43358d4a5662795513071"
927-
integrity sha512-ftegwQlGkyDCxZGhAVfMyWWXqpNhnyESvNY3oFAUV4eN6i/mmBTCSOQ5AX5VR5lr7PNYPWGO5sJ10Q5HeTPfgw==
924+
"@tensorflow/tfjs-converter@3.11.0":
925+
version "3.11.0"
926+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-converter/-/tfjs-converter-3.11.0.tgz#0842269a83599b52fd167a8a05372018a9a1ca6a"
927+
integrity sha512-rTRIKvBoqL0qdPYpm8UXauZycOiaBHZB2E2v3OoXoHnjvle/Xn/09uZJdrixgGhR+Kahs3Vz27BEEFz6RI5j2w==
928928

929-
"@tensorflow/tfjs-core@3.9.0":
930-
version "3.9.0"
931-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-core/-/tfjs-core-3.9.0.tgz#5ca2356a14a58263840a6e3caee2467780db9450"
932-
integrity sha512-wQ+VMsbvCne2OsogiNtRP8Mc01LnRGvAYQ0SGaDa4+1uwY2jsMk5GZjG66JQvf/Ppw8wyvKF170eh0yyCBgfcg==
929+
"@tensorflow/tfjs-core@3.11.0":
930+
version "3.11.0"
931+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-core/-/tfjs-core-3.11.0.tgz#1e3986533faaed922bbfc2fe86da506d0e9e5c79"
932+
integrity sha512-JOp+1+LCd0Xg3hu7fu6iQPWZnN8Hc6ssfP7B+625XH5GYY1/OhVASa7Ahe2mJr9gZovY2lw8FUejLh1jMmBb1Q==
933933
dependencies:
934934
"@types/long" "^4.0.1"
935935
"@types/offscreencanvas" "~2019.3.0"
@@ -939,30 +939,30 @@
939939
node-fetch "~2.6.1"
940940
seedrandom "2.4.3"
941941

942-
"@tensorflow/tfjs-data@3.9.0":
943-
version "3.9.0"
944-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-data/-/tfjs-data-3.9.0.tgz#9cb4fd6301c4362a8e7dc03bced563bdf1f0be19"
945-
integrity sha512-1/H9VlYlfEX/LflzobSB5sx3FCavWGmzqRnAyyn5ChjgCzIUa+RtJ7nYgK2+6RC2MIDgKt1jmu36mkKZrwPD3w==
942+
"@tensorflow/tfjs-data@3.11.0":
943+
version "3.11.0"
944+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-data/-/tfjs-data-3.11.0.tgz#90dd23a7181f0a744f2882a12c3442b27047383d"
945+
integrity sha512-+cUHUHzjM/zs0JVOwHQm9wP15Y+BZdRcUpMoYWia8r3kaGSyvoz6WqzacEP1PeXgJVnr2gtU3D+bF32th8fZfQ==
946946
dependencies:
947947
"@types/node-fetch" "^2.1.2"
948948
node-fetch "~2.6.1"
949949

950-
"@tensorflow/tfjs-layers@3.9.0":
951-
version "3.9.0"
952-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-layers/-/tfjs-layers-3.9.0.tgz#0e05116bcd7f55eb39cff322e9940fa46c9fbda2"
953-
integrity sha512-25I20Oy17YZ3y0x/pabeiN6/vai0vqMQ85/Bp0GLOpcN2kmOLcItdWOAqFW5YPI2nrTqnpNQyk9zhmIh8f6X4w==
954-
955-
"@tensorflow/tfjs@^3.9.0":
956-
version "3.9.0"
957-
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs/-/tfjs-3.9.0.tgz#ff3bcbfcb51800ea6791d7a7a020d354909d2c71"
958-
integrity sha512-TyykXiZ6r9rMoXbQZaAkOKJJUrJHQVAjH/K6XRCPpOG//Hf15ZW97ZODskEByj77yNMw4smFUWCFhprhY2PgDQ==
959-
dependencies:
960-
"@tensorflow/tfjs-backend-cpu" "3.9.0"
961-
"@tensorflow/tfjs-backend-webgl" "3.9.0"
962-
"@tensorflow/tfjs-converter" "3.9.0"
963-
"@tensorflow/tfjs-core" "3.9.0"
964-
"@tensorflow/tfjs-data" "3.9.0"
965-
"@tensorflow/tfjs-layers" "3.9.0"
950+
"@tensorflow/tfjs-layers@3.11.0":
951+
version "3.11.0"
952+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-layers/-/tfjs-layers-3.11.0.tgz#456d8dc3fe93937ced329d5d06310da294d3758c"
953+
integrity sha512-BtLgLucJZHv5te1K3yjT3iZdHXgMJArrLuOb/oRPOtTp4R2ad5N0V2m5RtuZJ3sI5/ah0h72xtmTWNyTv3/5dw==
954+
955+
"@tensorflow/tfjs@3.11.0":
956+
version "3.11.0"
957+
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs/-/tfjs-3.11.0.tgz#63d5231f41d57ca11b910664632a8e349eba3967"
958+
integrity sha512-TTYrKdkoh1sHnt4vn6MboLbpi1Es4U1Aw+L3PqwadRvXW4+7ySUtc00McrQ+ooK0q3Qhl3N7cvgchgM7nED3Mg==
959+
dependencies:
960+
"@tensorflow/tfjs-backend-cpu" "3.11.0"
961+
"@tensorflow/tfjs-backend-webgl" "3.11.0"
962+
"@tensorflow/tfjs-converter" "3.11.0"
963+
"@tensorflow/tfjs-core" "3.11.0"
964+
"@tensorflow/tfjs-data" "3.11.0"
965+
"@tensorflow/tfjs-layers" "3.11.0"
966966
argparse "^1.0.10"
967967
chalk "^4.1.0"
968968
core-js "3"
@@ -1033,10 +1033,10 @@
10331033
resolved "https://registry.yarnpkg.com/@types/webgl-ext/-/webgl-ext-0.0.30.tgz#0ce498c16a41a23d15289e0b844d945b25f0fb9d"
10341034
integrity sha512-LKVgNmBxN0BbljJrVUwkxwRYqzsAEPcZOe6S2T6ZaBDIrFp0qu4FNlpc5sM1tGbXUYFgdVQIoeLk1Y1UoblyEg==
10351035

1036-
"@types/[email protected].5":
1037-
version "0.0.5"
1038-
resolved "https://registry.yarnpkg.com/@types/webgl2/-/webgl2-0.0.5.tgz#dd925e20ab8ace80eb4b1e46fda5b109c508fb0d"
1039-
integrity sha512-oGaKsBbxQOY5+aJFV3KECDhGaXt+yZJt2y/OZsnQGLRkH6Fvr7rv4pCt3SRH1somIHfej/c4u7NSpCyd9x+1Ow==
1036+
"@types/[email protected].6":
1037+
version "0.0.6"
1038+
resolved "https://registry.yarnpkg.com/@types/webgl2/-/webgl2-0.0.6.tgz#1ea2db791362bd8521548d664dbd3c5311cdf4b6"
1039+
integrity sha512-50GQhDVTq/herLMiqSQkdtRu+d5q/cWHn4VvKJtrj4DJAjo1MNkWYa2MA41BaBO1q1HgsUjuQvEOk0QHvlnAaQ==
10401040

10411041
10421042
version "1.1.2"

danfojs-node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"types"
2121
],
2222
"dependencies": {
23-
"@tensorflow/tfjs-node": "3.6.1",
23+
"@tensorflow/tfjs-node": "3.11.0",
2424
"mathjs": "^9.4.4",
2525
"node-fetch": "^2.6.1",
2626
"papaparse": "^5.3.1",

danfojs-node/src/core/frame.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,8 +2045,10 @@ export default class DataFrame extends NDframe {
20452045
}
20462046

20472047
if (axis === 1) {
2048+
const colsAdded = [];
20482049
const newColumns = this.columns.map((col) => {
20492050
if (mapper[col] !== undefined) {
2051+
colsAdded.push(mapper[col]);
20502052
return mapper[col];
20512053
} else {
20522054
return col;
@@ -2055,6 +2057,9 @@ export default class DataFrame extends NDframe {
20552057

20562058
if (inplace) {
20572059
this.$setColumnNames(newColumns);
2060+
for (const col of colsAdded) {
2061+
this.$setInternalColumnDataProperty(col);
2062+
}
20582063
} else {
20592064
return new DataFrame([...this.values], {
20602065
index: [...this.index],
@@ -2289,6 +2294,7 @@ export default class DataFrame extends NDframe {
22892294
} else {
22902295
return new DataFrame(newData, {
22912296
index: newIndex,
2297+
columns: this.columns,
22922298
config: { ...this.config }
22932299
});
22942300
}

danfojs-node/tests/core/frame.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,15 @@ describe("DataFrame", function () {
10901090
df.query({ "column": "B", "is": ">=", "to": 5, inplace: true });
10911091
assert.deepEqual(df.index, [1, 2, 3]);
10921092
});
1093+
it("Confirms that column names are not changed", function () {
1094+
1095+
let data = [[1, 2, 3], [4, 5, 6], [20, 30, 40], [39, 89, 78]];
1096+
let cols = ["A", "B", "C"];
1097+
let df = new DataFrame(data, { columns: cols });
1098+
let df_query = df.query({ "column": "B", "is": ">=", "to": 5 });
1099+
assert.deepEqual(df_query.index, [1, 2, 3]);
1100+
assert.deepEqual(df_query.columns, ["A", "B", "C"]);
1101+
});
10931102

10941103
});
10951104

@@ -2043,6 +2052,28 @@ describe("DataFrame", function () {
20432052
assert.deepEqual(df.index, res);
20442053

20452054
});
2055+
it("Get new column via subseting works after rename (inplace)", function () {
2056+
let data = {
2057+
"A": [-20, 30, 47.3],
2058+
"B": [34, -4, 5],
2059+
"C": [20, 2, 30]
2060+
};
2061+
let df = new DataFrame(data);
2062+
df.rename({ mapper: { "A": "new_name" }, inplace: true });
2063+
df["new_name"].print();
2064+
assert.deepEqual(df["new_name"].values, data["A"]);
2065+
});
2066+
2067+
it("Get new column via subseting works after rename (not-inplace)", function () {
2068+
let data = {
2069+
"A": [-20, 30, 47.3],
2070+
"B": [34, -4, 5],
2071+
"C": [20, 2, 30]
2072+
};
2073+
let df = new DataFrame(data);
2074+
let new_df = df.rename({ mapper: { "A": "new_name" } });
2075+
assert.deepEqual(new_df["new_name"].values, data["A"]);
2076+
});
20462077
});
20472078

20482079
describe("sort_index", function () {

danfojs-node/types/core/frame.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,5 +551,5 @@ export class DataFrame extends NDframe implements DataFrameInterface {
551551
inplace?: boolean;
552552
}): DataFrame | void;
553553

554-
groupby(column: string): GroupBy;
554+
groupby(column: Array<string>): GroupBy;
555555
}

0 commit comments

Comments
 (0)