diff --git a/biome.json b/biome.json index 96f8afcd..353ba7be 100644 --- a/biome.json +++ b/biome.json @@ -41,7 +41,8 @@ "noUnusedVariables": "warn" }, "nursery": { - "all": true + "all": true, + "noSecrets": "off" }, "performance": { "all": true, diff --git a/src/core/pd_array.ts b/src/core/pd_array.ts index de891d94..c6d43e7b 100644 --- a/src/core/pd_array.ts +++ b/src/core/pd_array.ts @@ -88,46 +88,35 @@ function classifyScalar(v: Scalar): "date" | "bigint" | "float" | "int" | "strin } function inferDtype(data: readonly Scalar[]): DtypeName { - let hasFloat = false; - let hasInt = false; - let hasString = false; - let hasBool = false; - let hasDate = false; - let hasBigInt = false; - + const kinds = new Set<"date" | "bigint" | "float" | "int" | "string" | "bool">(); for (const v of data) { const kind = classifyScalar(v); - if (kind === "date") { - hasDate = true; - } else if (kind === "bigint") { - hasBigInt = true; - } else if (kind === "float") { - hasFloat = true; - } else if (kind === "int") { - hasInt = true; - } else if (kind === "string") { - hasString = true; - } else if (kind === "bool") { - hasBool = true; + if (kind !== null) { + kinds.add(kind); } } + return resolveDtype(kinds); +} - if (hasDate) { +function resolveDtype( + kinds: ReadonlySet<"date" | "bigint" | "float" | "int" | "string" | "bool">, +): DtypeName { + if (kinds.has("date")) { return "datetime"; } - if (hasBigInt) { + if (kinds.has("bigint")) { return "int64"; } - if (hasFloat) { + if (kinds.has("float")) { return "float64"; } - if (hasInt && !hasString && !hasBool) { + if (kinds.has("int") && !kinds.has("string") && !kinds.has("bool")) { return "int64"; } - if (hasBool && !hasInt && !hasFloat && !hasString) { + if (kinds.has("bool") && !kinds.has("int") && !kinds.has("float") && !kinds.has("string")) { return "bool"; } - if (hasString) { + if (kinds.has("string")) { return "string"; } return "object"; diff --git a/src/core/series.ts b/src/core/series.ts index 29063e91..a022e910 100644 --- a/src/core/series.ts +++ b/src/core/series.ts @@ -219,6 +219,16 @@ export class Series { readonly index: Index