Skip to content

Commit

Permalink
Merge pull request #320 from opensource9ja/misc/fixes
Browse files Browse the repository at this point in the history
Misc/fixes
  • Loading branch information
risenW authored Dec 5, 2021
2 parents 61dc2f7 + 91c22b5 commit 897705d
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 210 deletions.
2 changes: 1 addition & 1 deletion danfojs-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"types"
],
"dependencies": {
"@tensorflow/tfjs": "^3.9.0",
"@tensorflow/tfjs": "3.11.0",
"mathjs": "9.4.4",
"papaparse": "^5.3.1",
"request": "^2.88.2",
Expand Down
6 changes: 6 additions & 0 deletions danfojs-browser/src/core/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -2043,8 +2043,10 @@ export default class DataFrame extends NDframe {
}

if (axis === 1) {
const colsAdded = [];
const newColumns = this.columns.map((col) => {
if (mapper[col] !== undefined) {
colsAdded.push(mapper[col]);
return mapper[col];
} else {
return col;
Expand All @@ -2053,6 +2055,9 @@ export default class DataFrame extends NDframe {

if (inplace) {
this.$setColumnNames(newColumns);
for (const col of colsAdded) {
this.$setInternalColumnDataProperty(col);
}
} else {
return new DataFrame([...this.values], {
index: [...this.index],
Expand Down Expand Up @@ -2287,6 +2292,7 @@ export default class DataFrame extends NDframe {
} else {
return new DataFrame(newData, {
index: newIndex,
columns: this.columns,
config: { ...this.config }
});
}
Expand Down
31 changes: 31 additions & 0 deletions danfojs-browser/tests/core/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,15 @@ describe("DataFrame", function () {

assert.deepEqual(newdf.dtypes, dtype);
});
it("Confirms that column names are not changed", function () {

let data = [[1, 2, 3], [4, 5, 6], [20, 30, 40], [39, 89, 78]];
let cols = ["A", "B", "C"];
let df = new dfd.DataFrame(data, { columns: cols });
let df_query = df.query({ "column": "B", "is": ">=", "to": 5 });
assert.deepEqual(df_query.index, [1, 2, 3]);
assert.deepEqual(df_query.columns, ["A", "B", "C"]);
});

});

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

});

it("Get new column via subseting works after rename (inplace)", function () {
let data = {
"A": [-20, 30, 47.3],
"B": [34, -4, 5],
"C": [20, 2, 30]
};
let df = new dfd.DataFrame(data);
df.rename({ mapper: { "A": "new_name" }, inplace: true });
assert.deepEqual(df["new_name"].values, data["A"]);
});

it("Get new column via subseting works after rename (not-inplace)", function () {
let data = {
"A": [-20, 30, 47.3],
"B": [34, -4, 5],
"C": [20, 2, 30]
};
let df = new dfd.DataFrame(data);
let new_df = df.rename({ mapper: { "A": "new_name" } });
assert.deepEqual(new_df["new_name"].values, data["A"]);
});
});

describe("sort_index", function () {
Expand Down
2 changes: 1 addition & 1 deletion danfojs-browser/types/core/frame.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,5 +551,5 @@ export class DataFrame extends NDframe implements DataFrameInterface {
inplace?: boolean;
}): DataFrame | void;

groupby(column: string): GroupBy;
groupby(column: Array<string>): GroupBy;
}
84 changes: 42 additions & 42 deletions danfojs-browser/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -901,35 +901,35 @@
readdirp "^2.2.1"
upath "^1.1.1"

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

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

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

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

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

"@tensorflow/tfjs-layers@3.9.0":
version "3.9.0"
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-layers/-/tfjs-layers-3.9.0.tgz#0e05116bcd7f55eb39cff322e9940fa46c9fbda2"
integrity sha512-25I20Oy17YZ3y0x/pabeiN6/vai0vqMQ85/Bp0GLOpcN2kmOLcItdWOAqFW5YPI2nrTqnpNQyk9zhmIh8f6X4w==

"@tensorflow/tfjs@^3.9.0":
version "3.9.0"
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs/-/tfjs-3.9.0.tgz#ff3bcbfcb51800ea6791d7a7a020d354909d2c71"
integrity sha512-TyykXiZ6r9rMoXbQZaAkOKJJUrJHQVAjH/K6XRCPpOG//Hf15ZW97ZODskEByj77yNMw4smFUWCFhprhY2PgDQ==
dependencies:
"@tensorflow/tfjs-backend-cpu" "3.9.0"
"@tensorflow/tfjs-backend-webgl" "3.9.0"
"@tensorflow/tfjs-converter" "3.9.0"
"@tensorflow/tfjs-core" "3.9.0"
"@tensorflow/tfjs-data" "3.9.0"
"@tensorflow/tfjs-layers" "3.9.0"
"@tensorflow/tfjs-layers@3.11.0":
version "3.11.0"
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-layers/-/tfjs-layers-3.11.0.tgz#456d8dc3fe93937ced329d5d06310da294d3758c"
integrity sha512-BtLgLucJZHv5te1K3yjT3iZdHXgMJArrLuOb/oRPOtTp4R2ad5N0V2m5RtuZJ3sI5/ah0h72xtmTWNyTv3/5dw==

"@tensorflow/tfjs@3.11.0":
version "3.11.0"
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs/-/tfjs-3.11.0.tgz#63d5231f41d57ca11b910664632a8e349eba3967"
integrity sha512-TTYrKdkoh1sHnt4vn6MboLbpi1Es4U1Aw+L3PqwadRvXW4+7ySUtc00McrQ+ooK0q3Qhl3N7cvgchgM7nED3Mg==
dependencies:
"@tensorflow/tfjs-backend-cpu" "3.11.0"
"@tensorflow/tfjs-backend-webgl" "3.11.0"
"@tensorflow/tfjs-converter" "3.11.0"
"@tensorflow/tfjs-core" "3.11.0"
"@tensorflow/tfjs-data" "3.11.0"
"@tensorflow/tfjs-layers" "3.11.0"
argparse "^1.0.10"
chalk "^4.1.0"
core-js "3"
Expand Down Expand Up @@ -1033,10 +1033,10 @@
resolved "https://registry.yarnpkg.com/@types/webgl-ext/-/webgl-ext-0.0.30.tgz#0ce498c16a41a23d15289e0b844d945b25f0fb9d"
integrity sha512-LKVgNmBxN0BbljJrVUwkxwRYqzsAEPcZOe6S2T6ZaBDIrFp0qu4FNlpc5sM1tGbXUYFgdVQIoeLk1Y1UoblyEg==

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

"@ungap/[email protected]":
version "1.1.2"
Expand Down
2 changes: 1 addition & 1 deletion danfojs-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"types"
],
"dependencies": {
"@tensorflow/tfjs-node": "3.6.1",
"@tensorflow/tfjs-node": "3.11.0",
"mathjs": "^9.4.4",
"node-fetch": "^2.6.1",
"papaparse": "^5.3.1",
Expand Down
6 changes: 6 additions & 0 deletions danfojs-node/src/core/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -2045,8 +2045,10 @@ export default class DataFrame extends NDframe {
}

if (axis === 1) {
const colsAdded = [];
const newColumns = this.columns.map((col) => {
if (mapper[col] !== undefined) {
colsAdded.push(mapper[col]);
return mapper[col];
} else {
return col;
Expand All @@ -2055,6 +2057,9 @@ export default class DataFrame extends NDframe {

if (inplace) {
this.$setColumnNames(newColumns);
for (const col of colsAdded) {
this.$setInternalColumnDataProperty(col);
}
} else {
return new DataFrame([...this.values], {
index: [...this.index],
Expand Down Expand Up @@ -2289,6 +2294,7 @@ export default class DataFrame extends NDframe {
} else {
return new DataFrame(newData, {
index: newIndex,
columns: this.columns,
config: { ...this.config }
});
}
Expand Down
31 changes: 31 additions & 0 deletions danfojs-node/tests/core/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,15 @@ describe("DataFrame", function () {
df.query({ "column": "B", "is": ">=", "to": 5, inplace: true });
assert.deepEqual(df.index, [1, 2, 3]);
});
it("Confirms that column names are not changed", function () {

let data = [[1, 2, 3], [4, 5, 6], [20, 30, 40], [39, 89, 78]];
let cols = ["A", "B", "C"];
let df = new DataFrame(data, { columns: cols });
let df_query = df.query({ "column": "B", "is": ">=", "to": 5 });
assert.deepEqual(df_query.index, [1, 2, 3]);
assert.deepEqual(df_query.columns, ["A", "B", "C"]);
});

});

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

});
it("Get new column via subseting works after rename (inplace)", function () {
let data = {
"A": [-20, 30, 47.3],
"B": [34, -4, 5],
"C": [20, 2, 30]
};
let df = new DataFrame(data);
df.rename({ mapper: { "A": "new_name" }, inplace: true });
df["new_name"].print();
assert.deepEqual(df["new_name"].values, data["A"]);
});

it("Get new column via subseting works after rename (not-inplace)", function () {
let data = {
"A": [-20, 30, 47.3],
"B": [34, -4, 5],
"C": [20, 2, 30]
};
let df = new DataFrame(data);
let new_df = df.rename({ mapper: { "A": "new_name" } });
assert.deepEqual(new_df["new_name"].values, data["A"]);
});
});

describe("sort_index", function () {
Expand Down
2 changes: 1 addition & 1 deletion danfojs-node/types/core/frame.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,5 +551,5 @@ export class DataFrame extends NDframe implements DataFrameInterface {
inplace?: boolean;
}): DataFrame | void;

groupby(column: string): GroupBy;
groupby(column: Array<string>): GroupBy;
}
Loading

0 comments on commit 897705d

Please sign in to comment.