|
25 | 25 | import type { Label, Scalar } from "../types.ts"; |
26 | 26 | import { Index } from "./base-index.ts"; |
27 | 27 | import { DataFrame } from "./frame.ts"; |
28 | | -import { Series } from "./series.ts"; |
| 28 | +import type { Series } from "./series.ts"; |
29 | 29 |
|
30 | 30 | // ─── public types ────────────────────────────────────────────────────────────── |
31 | 31 |
|
32 | 32 | /** Orient values supported by {@link toDictOriented}. */ |
33 | | -export type ToDictOrient = "dict" | "columns" | "list" | "series" | "split" | "tight" | "records" | "index"; |
| 33 | +export type ToDictOrient = |
| 34 | + | "dict" |
| 35 | + | "columns" |
| 36 | + | "list" |
| 37 | + | "series" |
| 38 | + | "split" |
| 39 | + | "tight" |
| 40 | + | "records" |
| 41 | + | "index"; |
34 | 42 |
|
35 | 43 | /** Orient values supported by {@link fromDictOriented}. */ |
36 | 44 | export type FromDictOrient = "columns" | "index" | "split" | "tight"; |
@@ -78,17 +86,23 @@ function isDefaultRange(labels: readonly Label[]): boolean { |
78 | 86 | * @param df Source DataFrame. |
79 | 87 | * @param orient Output structure. Defaults to `"dict"`. |
80 | 88 | */ |
81 | | -export function toDictOriented(df: DataFrame, orient: "dict" | "columns"): Record<string, Record<string, Scalar>>; |
| 89 | +export function toDictOriented( |
| 90 | + df: DataFrame, |
| 91 | + orient: "dict" | "columns", |
| 92 | +): Record<string, Record<string, Scalar>>; |
82 | 93 | export function toDictOriented(df: DataFrame, orient: "list"): Record<string, Scalar[]>; |
83 | 94 | export function toDictOriented(df: DataFrame, orient: "series"): Record<string, Series<Scalar>>; |
84 | 95 | export function toDictOriented(df: DataFrame, orient: "split"): DictSplit; |
85 | 96 | export function toDictOriented(df: DataFrame, orient: "tight"): DictTight; |
86 | 97 | export function toDictOriented(df: DataFrame, orient: "records"): Record<string, Scalar>[]; |
87 | | -export function toDictOriented(df: DataFrame, orient: "index"): Record<string, Record<string, Scalar>>; |
| 98 | +export function toDictOriented( |
| 99 | + df: DataFrame, |
| 100 | + orient: "index", |
| 101 | +): Record<string, Record<string, Scalar>>; |
88 | 102 | export function toDictOriented( |
89 | 103 | df: DataFrame, |
90 | 104 | orient: ToDictOrient = "dict", |
91 | | -): Record<string, unknown> | unknown[] { |
| 105 | +): Record<string, unknown> | unknown[] | DictSplit | DictTight { |
92 | 106 | const colNames = [...df.columns.values]; |
93 | 107 | const rowLabels = [...(df.index.values as Label[])]; |
94 | 108 | const nRows = df.index.size; |
@@ -201,10 +215,7 @@ export function fromDictOriented( |
201 | 215 | orient: "index", |
202 | 216 | ): DataFrame; |
203 | 217 | export function fromDictOriented(data: SplitInput, orient: "split" | "tight"): DataFrame; |
204 | | -export function fromDictOriented( |
205 | | - data: unknown, |
206 | | - orient: FromDictOrient = "columns", |
207 | | -): DataFrame { |
| 218 | +export function fromDictOriented(data: unknown, orient: FromDictOrient = "columns"): DataFrame { |
208 | 219 | switch (orient) { |
209 | 220 | case "columns": { |
210 | 221 | const colsData = data as Record<string, readonly Scalar[]>; |
@@ -266,8 +277,11 @@ function buildFromSplit(input: SplitInput): DataFrame { |
266 | 277 | for (const row of data) { |
267 | 278 | for (let j = 0; j < columns.length; j++) { |
268 | 279 | const col = columns[j]; |
| 280 | + if (col === undefined) { |
| 281 | + continue; |
| 282 | + } |
269 | 283 | const arr = colArrays[col]; |
270 | | - if (col !== undefined && arr !== undefined) { |
| 284 | + if (arr !== undefined) { |
271 | 285 | arr.push(row[j] ?? null); |
272 | 286 | } |
273 | 287 | } |
|
0 commit comments