Skip to content

Commit a6d0372

Browse files
authored
Merge branch 'dev' into pct_change-port
2 parents 9a058d9 + b712f70 commit a6d0372

23 files changed

Lines changed: 1411 additions & 1260 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ yarn add danfojs
7070
For use directly in HTML files, you can add the latest script tag from [JsDelivr](https://www.jsdelivr.com/package/npm/danfojs) to your HTML file:
7171

7272
```html
73-
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.0.2/lib/bundle.js"></script>
73+
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.0.3/lib/bundle.js"></script>
7474
```
7575
See all available versions [here](https://www.jsdelivr.com/package/npm/danfojs)
7676

@@ -85,7 +85,7 @@ See all available versions [here](https://www.jsdelivr.com/package/npm/danfojs)
8585
<head>
8686
<meta charset="UTF-8" />
8787
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
88-
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.0.2/lib/bundle.js"></script>
88+
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.0.3/lib/bundle.js"></script>
8989

9090
<title>Document</title>
9191
</head>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "danfo",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"private": true,
55
"workspaces": [
66
"danfojs-node/**",

src/danfojs-base/core/generic.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ export default class NDframe implements NDframeInterface {
7272
}
7373

7474
if (data === undefined || (Array.isArray(data) && data.length === 0)) {
75-
this.loadArrayIntoNdframe({ data: [], index: [], columns: [], dtypes: [] });
75+
if (columns === undefined) columns = [];
76+
if (dtypes === undefined) dtypes = [];
77+
if (columns.length === 0 && dtypes.length !== 0) ErrorThrower.throwDtypeWithoutColumnError();
78+
this.loadArrayIntoNdframe({ data: [], index: [], columns: columns, dtypes: dtypes });
7679
} else if (utils.is1DArray(data)) {
7780
this.loadArrayIntoNdframe({ data, index, columns, dtypes });
7881
} else {
@@ -306,6 +309,7 @@ export default class NDframe implements NDframeInterface {
306309
*/
307310
$setColumnNames(columns?: string[]) {
308311

312+
// console.log(columns);
309313
if (this.$isSeries) {
310314
if (columns) {
311315
if (this.$data.length != 0 && columns.length != 1 && typeof columns != 'string') {
@@ -322,7 +326,7 @@ export default class NDframe implements NDframeInterface {
322326

323327
ErrorThrower.throwColumnNamesLengthError(this, columns)
324328
}
325-
if (Array.from(new Set(columns)).length !== this.shape[1]) {
329+
if (Array.from(new Set(columns)).length !== columns.length) {
326330
ErrorThrower.throwColumnDuplicateError()
327331
}
328332

@@ -337,7 +341,10 @@ export default class NDframe implements NDframeInterface {
337341
* Returns the shape of the NDFrame. Shape is determined by [row length, column length]
338342
*/
339343
get shape(): Array<number> {
340-
if (this.$data.length === 0) return [0, 0]
344+
if (this.$data.length === 0) {
345+
if (this.$columns.length === 0) return [0, 0];
346+
else return [0, this.$columns.length];
347+
}
341348
if (this.$isSeries) {
342349
return [this.$data.length, 1];
343350
} else {

src/danfojs-base/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import merge from "./transformers/merge"
2929
import dateRange from "./core/daterange"
3030
import tensorflow from "./shared/tensorflowlib"
3131

32-
const __version = "1.0.2";
32+
const __version = "1.0.3";
3333

3434
export {
3535
NDframe,

src/danfojs-base/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "danfojs-base",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Base package used in danfojs-node and danfojs-browser",
55
"main": "index.ts",
66
"scripts": {
@@ -45,7 +45,7 @@
4545
"eslint": "^7.1.0",
4646
"ify-loader": "^1.1.0",
4747
"install-peers": "^1.0.3",
48-
"karma": "6.3.14",
48+
"karma": "6.3.16",
4949
"karma-browserify": "7.0.0",
5050
"karma-chai": "^0.1.0",
5151
"karma-chrome-launcher": "^3.1.0",

src/danfojs-base/shared/errors.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ class ErrorThrower {
5151
throw new Error(msg)
5252
}
5353

54+
throwDtypeWithoutColumnError = (): void => {
55+
const msg = `DtypeError: columns parameter must be provided when dtypes parameter is provided`
56+
throw new Error(msg)
57+
}
58+
5459
throwColumnLengthError = (ndframe: NDframe | DataFrame, arrLen: number): void => {
5560
const msg = `ParamError: Column data length mismatch. You provided data with length ${arrLen} but Ndframe has column of length ${ndframe.shape[1]}`
5661
throw new Error(msg)

src/danfojs-base/yarn.lock

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4412,10 +4412,10 @@ karma-mocha@^2.0.1:
44124412
dependencies:
44134413
minimist "^1.2.3"
44144414

4415-
karma@6.3.14:
4416-
version "6.3.14"
4417-
resolved "https://registry.yarnpkg.com/karma/-/karma-6.3.14.tgz#1ed57a489249b9260bc604325ae333766d4cddc9"
4418-
integrity sha512-SDFoU5F4LdosEiUVWUDRPCV/C1zQRNtIakx7rWkigf7R4sxGADlSEeOma4S1f/js7YAzvqLW92ByoiQptg+8oQ==
4415+
karma@6.3.16:
4416+
version "6.3.16"
4417+
resolved "https://registry.yarnpkg.com/karma/-/karma-6.3.16.tgz#76d1a705fd1cf864ee5ed85270b572641e0958ef"
4418+
integrity sha512-nEU50jLvDe5yvXqkEJRf8IuvddUkOY2x5Xc4WXHz6dxINgGDrgD2uqQWeVrJs4hbfNaotn+HQ1LZJ4yOXrL7xQ==
44194419
dependencies:
44204420
body-parser "^1.19.0"
44214421
braces "^3.0.2"
@@ -4432,6 +4432,7 @@ karma@6.3.14:
44324432
log4js "^6.4.1"
44334433
mime "^2.5.2"
44344434
minimatch "^3.0.4"
4435+
mkdirp "^0.5.5"
44354436
qjobs "^1.2.0"
44364437
range-parser "^1.2.1"
44374438
rimraf "^3.0.2"

src/danfojs-browser/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ yarn add danfojs
7171
For use directly in HTML files, you can add the latest script tag from [JsDelivr](https://www.jsdelivr.com/package/npm/danfojs) to your HTML file:
7272

7373
```html
74-
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.0.2/lib/bundle.js"></script>
74+
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.0.3/lib/bundle.js"></script>
7575
```
7676
See all available versions [here](https://www.jsdelivr.com/package/npm/danfojs)
7777

@@ -86,7 +86,7 @@ See all available versions [here](https://www.jsdelivr.com/package/npm/danfojs)
8686
<head>
8787
<meta charset="UTF-8" />
8888
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
89-
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.0.2/lib/bundle.js"></script>
89+
<script src="https://cdn.jsdelivr.net/npm/danfojs@1.0.3/lib/bundle.js"></script>
9090

9191
<title>Document</title>
9292
</head>

src/danfojs-browser/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"name": "danfojs",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "JavaScript library providing high performance, intuitive, and easy to use data structures for manipulating and processing structured data.",
55
"main": "dist/danfojs-browser/src/index.js",
66
"types": "dist/danfojs-browser/src/index.d.ts",
7+
"module": "lib/bundle-esm.js",
78
"directories": {
89
"test": "tests"
910
},
@@ -89,7 +90,7 @@
8990
"ify-loader": "^1.1.0",
9091
"install-peers": "^1.0.3",
9192
"json-loader": "^0.5.7",
92-
"karma": "6.3.14",
93+
"karma": "6.3.16",
9394
"karma-browserify": "7.0.0",
9495
"karma-chai": "^0.1.0",
9596
"karma-chrome-launcher": "^3.1.0",
@@ -99,8 +100,8 @@
99100
"source-map-loader": "^3.0.0",
100101
"ts-loader": "^9.2.6",
101102
"typescript": "^4.4.2",
102-
"webpack": "5.21.2",
103-
"webpack-cli": "4.5.0",
103+
"webpack": "5.69.1",
104+
"webpack-cli": "4.9.2",
104105
"yarn": "^1.22.10"
105106
},
106107
"nyc": {
@@ -110,4 +111,4 @@
110111
]
111112
},
112113
"sideEffects": false
113-
}
114+
}

src/danfojs-browser/tests/core/frame.test.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,51 @@ describe("DataFrame", function () {
10631063
});
10641064
});
10651065

1066+
describe("diff", function () {
1067+
it("Return same DataFrame if other === 0", function () {
1068+
const data = [ [ 0, 2, 4 ], [ 10, 10, 10 ], [ 1, 2, 3 ] ];
1069+
const df = new dfd.DataFrame(data);
1070+
assert.deepEqual((df.diff(0)).values, [ [ 0, 2, 4 ], [ 10, 10, 10 ], [ 1, 2, 3 ] ]);
1071+
});
1072+
it("Return difference of DataFrame with previous row", function () {
1073+
const data = [ [ 0, 2, 4 ], [ 10, 10, 10 ], [ 1, 2, 3 ] ];
1074+
const df = new dfd.DataFrame(data);
1075+
assert.deepEqual((df.diff(1)).values, [ [ NaN, NaN, NaN ], [ 10, 8, 6 ], [ -9, -8, -7 ] ]);
1076+
});
1077+
it("Return difference of DataFrame with following row", function () {
1078+
const data = [ [ 0, 2, 4 ], [ 10, 10, 10 ], [ 1, 2, 3 ] ];
1079+
const df = new dfd.DataFrame(data);
1080+
assert.deepEqual((df.diff(-1)).values, [ [ -10, -8, -6 ], [ 9, 8, 7 ], [ NaN, NaN, NaN ] ]);
1081+
});
1082+
it("Return difference of a DataFrame with a Series along default axis 1", function () {
1083+
const data = [ [ 0, 2, 4 ], [ 10, 10, 10 ], [ 1, 2, 3 ] ];
1084+
const sf = new dfd.Series([ 1, 2, 1 ]);
1085+
const df = new dfd.DataFrame(data);
1086+
assert.deepEqual((df.diff(sf)).values, [ [ -1, 0, 3 ], [ 9, 8, 9 ], [ 0, 0, 2 ] ]);
1087+
});
1088+
it("Return difference of a DataFrame with along axis 0 (column-wise), previous column", function () {
1089+
const data = [ [ 0, 2, 4 ], [ 10, 10, 10 ], [ 1, 2, 3 ] ];
1090+
const df = new dfd.DataFrame(data);
1091+
assert.deepEqual((df.diff(1, { axis: 0 })).values, [ [ NaN, 2, 2 ], [ NaN, 0, 0 ], [ NaN, 1, 1 ] ]);
1092+
});
1093+
it("Return difference of a DataFrame with along axis 0 (column-wise), following column", function () {
1094+
const data = [ [ 0, 2, 4 ], [ 10, 10, 10 ], [ 1, 2, 3 ] ];
1095+
const df = new dfd.DataFrame(data);
1096+
assert.deepEqual((df.diff(-1, { axis: 0 })).values, [ [ -2, -2, NaN ], [ 0, 0, NaN ], [ -1, -1, NaN ] ]);
1097+
});
1098+
it("Return difference of a DataFrame with another DataFrame along default axis 1", function () {
1099+
const df1 = new dfd.DataFrame([ [ 0, 2, 4 ], [ 3, 10, 4 ] ]);
1100+
const df2 = new dfd.DataFrame([ [ -1, -2, 4 ], [ 10, 5, 0 ] ]);
1101+
assert.deepEqual((df1.diff(df2)).values, [ [ 1, 4, 0 ], [ -7, 5, 4 ] ]);
1102+
});
1103+
it("Throw error if DataFrame for diff contains string", function () {
1104+
const df = new dfd.DataFrame([ [ "words", "words", "words" ], [ "words", "words", "words" ] ]);
1105+
assert.throws(() => {
1106+
df.diff(1);
1107+
}, Error, "TypeError: diff operation is not supported for string dtypes");
1108+
});
1109+
});
1110+
10661111
describe("mean", function () {
10671112
it("Returns the mean of a DataFrame (Default axis is [1:column])", function () {
10681113
const data = [ [ 0, 2, 4 ],

0 commit comments

Comments
 (0)