MCPcopy Index your code
hub / github.com/javascriptdata/danfojs / $typeChecker

Method $typeChecker

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

* Private type checker used by inferDtype function * @param arr The array

(arr: ArrayType1D | ArrayType2D)

Source from the content-addressed store, hash-verified

275 * @param arr The array
276 */
277 private $typeChecker(arr: ArrayType1D | ArrayType2D) {
278 let dtypes: string;
279 let lim: number;
280 let intTracker: Array<boolean> = [];
281 let floatTracker: Array<boolean> = [];
282 let stringTracker: Array<boolean> = [];
283 let boolTracker: Array<boolean> = [];
284 let dateTracker: Array<boolean> = [];
285
286 if (arr.length < config.getDtypeTestLim) {
287 lim = arr.length;
288 } else {
289 lim = config.getDtypeTestLim;
290 }
291
292 const arrSlice = arr.slice(0, lim);
293
294 for (let i = 0; i < lim; i++) {
295 const ele = arrSlice[i];
296 if (typeof ele == "boolean") {
297 floatTracker.push(false);
298 intTracker.push(false);
299 stringTracker.push(false);
300 boolTracker.push(true);
301 dateTracker.push(false);
302 } else if (this.isEmpty(ele)) {
303 floatTracker.push(true);
304 intTracker.push(false);
305 stringTracker.push(false);
306 boolTracker.push(false);
307 dateTracker.push(false);
308 } else if (this.isDate(ele)) {
309 floatTracker.push(false);
310 intTracker.push(false);
311 stringTracker.push(false);
312 boolTracker.push(false);
313 dateTracker.push(true);
314 } else if (!isNaN(Number(ele))) {
315 if ((ele as unknown as string).toString().includes(".")) {
316 floatTracker.push(true);
317 intTracker.push(false);
318 stringTracker.push(false);
319 boolTracker.push(false);
320 dateTracker.push(false);
321 } else {
322 floatTracker.push(false);
323 intTracker.push(true);
324 stringTracker.push(false);
325 boolTracker.push(false);
326 dateTracker.push(false);
327 }
328 } else {
329 floatTracker.push(false);
330 intTracker.push(false);
331 stringTracker.push(true);
332 boolTracker.push(false);
333 dateTracker.push(false);
334 }

Callers 1

inferDtypeMethod · 0.95

Calls 5

isEmptyMethod · 0.95
isDateMethod · 0.95
sliceMethod · 0.80
includesMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected