From f5e6375f9c7bc1fc247cffc76faa0e47b6b18b8d Mon Sep 17 00:00:00 2001 From: Rising Odegua Date: Thu, 3 Apr 2025 21:19:45 +0100 Subject: [PATCH] fix isEmpty bug with bigInt --- src/danfojs-base/shared/utils.ts | 19 +++++++++++-- src/danfojs-node/test/utils.test.ts | 43 +++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/danfojs-base/shared/utils.ts b/src/danfojs-base/shared/utils.ts index e0553863..8dc4de8e 100644 --- a/src/danfojs-base/shared/utils.ts +++ b/src/danfojs-base/shared/utils.ts @@ -86,12 +86,25 @@ export default class Utils { } /** - * Checks if a value is empty. Empty means it's either null, undefined or NaN + * Checks if a value is empty. Empty means it's either null, undefined or NaN. + * Empty strings are NOT considered empty. * @param value The value to check. - * @returns + * @returns boolean indicating if the value is empty */ isEmpty(value: T): boolean { - return value === undefined || value === null || (isNaN(value as any) && typeof value !== "string"); + if (value === undefined || value === null) { + return true; + } + + if (typeof value === 'bigint') { + return false; // BigInt values are never considered empty + } + + if (typeof value === 'number') { + return isNaN(value); + } + + return false; // All other types (strings, objects, arrays, etc) are not considered empty } /** diff --git a/src/danfojs-node/test/utils.test.ts b/src/danfojs-node/test/utils.test.ts index a8d08fe5..0a8da92d 100644 --- a/src/danfojs-node/test/utils.test.ts +++ b/src/danfojs-node/test/utils.test.ts @@ -40,6 +40,49 @@ describe("Utils", function () { assert.isTrue(utils.isUndefined(arr)); }); + describe("isEmpty", function () { + it("should return true for null values", function () { + assert.isTrue(utils.isEmpty(null)); + }); + + it("should return true for undefined values", function () { + assert.isTrue(utils.isEmpty(undefined)); + }); + + it("should return true for NaN values", function () { + assert.isTrue(utils.isEmpty(NaN)); + }); + + it("should return false for strings (including empty strings)", function () { + assert.isFalse(utils.isEmpty("")); + assert.isFalse(utils.isEmpty(" ")); + assert.isFalse(utils.isEmpty("hello")); + }); + + it("should return false for numbers (except NaN)", function () { + assert.isFalse(utils.isEmpty(0)); + assert.isFalse(utils.isEmpty(-1)); + assert.isFalse(utils.isEmpty(42.5)); + }); + + it("should return false for BigInt values", function () { + assert.isFalse(utils.isEmpty(BigInt(9007199254740991))); + assert.isFalse(utils.isEmpty(BigInt(0))); + }); + + it("should return false for objects and arrays", function () { + assert.isFalse(utils.isEmpty({})); + assert.isFalse(utils.isEmpty([])); + assert.isFalse(utils.isEmpty({ key: "value" })); + assert.isFalse(utils.isEmpty([1, 2, 3])); + }); + + it("should return false for boolean values", function () { + assert.isFalse(utils.isEmpty(true)); + assert.isFalse(utils.isEmpty(false)); + }); + }); + it("Checks if value is a valid Date object", function () { let date1 = new Date(); let date2 = "2021-01-01 00:00:00";