MCPcopy Index your code
hub / github.com/javascriptdata/danfojs / replaceUndefinedWithNaN

Method replaceUndefinedWithNaN

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

* Replaces all missing values with NaN. Missing values are undefined, Null and Infinity * @param arr The array * @param isSeries Whether the arr is a series or not

(arr: ArrayType1D | ArrayType2D, isSeries: boolean)

Source from the content-addressed store, hash-verified

213 * @param isSeries Whether the arr is a series or not
214 */
215 replaceUndefinedWithNaN(arr: ArrayType1D | ArrayType2D, isSeries: boolean): ArrayType1D | ArrayType2D {
216 if (arr.length === 0) return arr;
217
218 if (isSeries && Array.isArray(arr)) {
219 const newArr = arr.map((ele) => {
220 if (typeof ele === "undefined") {
221 return NaN;
222 }
223 if (typeof ele === "number" && (isNaN(ele) || ele == Infinity)) {
224 return NaN;
225 }
226 if (ele == null) {
227 return NaN;
228 }
229 return ele
230 });
231 return newArr as ArrayType1D
232 } else {
233 const newArr = []
234 if (Array.isArray(arr)) {
235 for (let i = 0; i < arr.length; i++) {
236 const innerArr = arr[i]
237 const temp = (innerArr as unknown as ArrayType2D).map((ele: any) => {
238 if (typeof ele === "undefined") {
239 return NaN;
240 }
241 if (typeof ele === "number" && (isNaN(ele) || ele == Infinity)) {
242 return NaN;
243 }
244 if (ele == null) {
245 return NaN;
246 }
247 return ele
248 });
249 newArr.push(temp);
250 }
251 }
252 return newArr;
253 }
254 }
255
256 /**
257 * Infer data type from an array or array of arrays

Callers 2

utils.test.jsFile · 0.80
utils.test.tsFile · 0.80

Calls 1

mapMethod · 0.65

Tested by

no test coverage detected