Skip to content

Commit 51ab8d6

Browse files
committed
update types for NaN columns
1 parent 11cfe87 commit 51ab8d6

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

danfojs/src/core/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,13 @@ export class Utils {
306306
let string_tracker = []
307307
let bool_tracker = []
308308

309-
//remove NaNs from array
309+
//remove NaNs from array before checking dtype
310310
let arr = []
311311
ele.map(val => {
312312
if (!(isNaN(val) && typeof val != "string")) {
313313
arr.push(val)
314+
}else{
315+
arr.push("NaN") //set NaN to string and return dtype ""string". The caller should explicitly convert the dtype
314316
}
315317
})
316318

@@ -321,6 +323,7 @@ export class Utils {
321323
int_tracker.push(false)
322324
string_tracker.push(false)
323325
bool_tracker.push(true)
326+
324327
} else if (!isNaN(Number(ele))) {
325328

326329
if (ele.toString().includes(".")) {

danfojs/tests/core/utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ describe("Utils Functions", function () {
9191
let result = ['boolean', 'string', 'int32']
9292
assert.deepEqual(utils.__get_t(data), result)
9393
})
94+
it("Returns string type if values are NaN", function () {
95+
let data = [[true, false, true], ["boy", "girl", "boy"], [NaN, undefined, NaN]]
96+
let result = ['boolean', 'string', 'string']
97+
assert.deepEqual(utils.__get_t(data), result)
98+
})
9499
})
95100

96101
describe("__map_int_to_bool", function () {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"table": "^5.4.6"
2424
},
2525
"scripts": {
26-
"test": "nyc mocha --require @babel/register danfojs/tests/core/frame",
26+
"test": "nyc mocha --require @babel/register danfojs/tests/core/utils",
2727
"dev": "npm run lint && babel ./danfojs/src -d dist --no-comments",
2828
"build": "babel ./danfojs/src -d ./dist --no-comments",
2929
"lint": "eslint ./danfojs/src",

0 commit comments

Comments
 (0)