diff --git a/src/danfojs-base/core/generic.ts b/src/danfojs-base/core/generic.ts index f4f68cae..a82898ad 100644 --- a/src/danfojs-base/core/generic.ts +++ b/src/danfojs-base/core/generic.ts @@ -285,7 +285,7 @@ export default class NDframe implements NDframeInterface { this.$index = index } else { - this.$index = utils.range(0, this.shape[0] - 1) //generate index + this.$index = utils.erange(0, this.shape[0]) //generate index } } @@ -293,7 +293,7 @@ export default class NDframe implements NDframeInterface { * Internal function to reset the index of the NDFrame using a range of indices. */ $resetIndex(): void { - this.$index = utils.range(0, this.shape[0] - 1) + this.$index = utils.erange(0, this.shape[0]) } /** @@ -333,7 +333,7 @@ export default class NDframe implements NDframeInterface { this.$columns = columns } else { - this.$columns = (utils.range(0, this.shape[1] - 1)).map((val) => `${val}`) //generate columns + this.$columns = (utils.erange(0, this.shape[1])).map((val) => `${val}`) //generate columns } } } diff --git a/src/danfojs-base/shared/utils.ts b/src/danfojs-base/shared/utils.ts index e0553863..8b048f11 100644 --- a/src/danfojs-base/shared/utils.ts +++ b/src/danfojs-base/shared/utils.ts @@ -124,6 +124,19 @@ export default class Utils { return arr; } + /** + * Generates an array of integers between specified range with exclusive end + * @param start The starting number. + * @param end The exclusive end number. + */ + erange(start: number, end: number): Array { + const arr = []; + for (let i = start; i < end; i++) { + arr.push(i); + } + return arr; + } + /** * Checks if object has the specified key * @param obj The object to check.