MCPcopy Create free account
hub / github.com/javascriptdata/danfojs / countNaNs

Method countNaNs

src/danfojs-base/shared/utils.ts:401–442  ·  view source on GitHub ↗

* Count the NaN and non-NaN values present in an array * @param arr Array object * @param val whether to return the value count instead of the null count * @param isSeries Whether the array is of type series or not

(arr: ArrayType1D | ArrayType2D, returnVal: boolean = true, isSeries: boolean)

Source from the content-addressed store, hash-verified

399 * @param isSeries Whether the array is of type series or not
400 */
401 countNaNs(arr: ArrayType1D | ArrayType2D, returnVal: boolean = true, isSeries: boolean): number | Array<number> {
402 if (isSeries) {
403 let nullCount = 0;
404 let valCount = 0;
405 for (let i = 0; i < arr.length; i++) {
406 const ele = arr[i];
407 if (Number.isNaN(ele)) {
408 nullCount = nullCount + 1;
409 } else {
410 valCount = valCount + 1;
411 }
412
413 }
414 if (returnVal) {
415 return valCount;
416 } else {
417 return nullCount;
418 }
419 } else {
420 const resultArr = [];
421 for (let i = 0; i < arr.length; i++) {
422 const innerArr = arr[i];
423 let nullCount = 0;
424 let valCount = 0;
425 for (let i = 0; i < (innerArr as unknown as ArrayType2D).length; i++) {
426 const ele = (innerArr as unknown as ArrayType2D)[i];
427 if (Number.isNaN(ele)) {
428 nullCount = nullCount + 1;
429 } else {
430 valCount = valCount + 1;
431 }
432 }
433
434 if (returnVal) {
435 resultArr.push(valCount);
436 } else {
437 resultArr.push(nullCount);
438 }
439 }
440 return resultArr;
441 }
442 }
443
444 /**
445 * Round elements of an array or array of arrays to specified dp

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected