Skip to content

Commit 112e575

Browse files
Copilotmrjf
andauthored
Fix CI: resolve typecheck errors, lint errors, and formatting issues
Typecheck fixes: - to_from_dict.ts: fix overload signature compatibility and undefined index type - string_ops.ts: widen StrInput type to accept readonly Scalar[] - string_ops_extended.ts: fix overload compatibility via StrInput widening - where_mask.ts: use Index.contains() instead of non-existent indexOf() - notna_isna.test.ts: add dfFromMap helper for proper 2-arg DataFrame constructor - string_ops.test.ts: use spread to copy readonly array before sort - window_extended.test.ts: use .values instead of .toArray() on SeriesLike Lint fixes: - biome.json: add overrides for benchmarks (noConsole) and tests (useLiteralKeys) - api_types.ts: use typed casts instead of Record index access - string_ops.ts: replace forEach with for-of, refactor assign-in-expression - string_ops_extended.ts: refactor assign-in-expression in extractGroupNames - numeric_extended.ts: remove useless else after return - window_extended.ts: remove useless switch case before default - numeric_extended.test.ts: replace non-null assertions with nullish coalescing - rolling_apply.test.ts: replace non-null assertions with nullish coalescing - format_ops.test.ts: use Number.POSITIVE_INFINITY, fix approximate constants Formatting: - Apply biome format --write across all affected files Agent-Logs-Url: https://github.com/githubnext/tsessebe/sessions/4d41059e-6981-42f5-b701-befb01f01bb8 Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
1 parent 99e4cce commit 112e575

37 files changed

Lines changed: 590 additions & 407 deletions

benchmarks/tsb/bench_dataframe_dropna.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ const ROWS = 100_000;
77
const WARMUP = 5;
88
const ITERATIONS = 20;
99

10-
const a: (number | null)[] = Array.from({ length: ROWS }, (_, i) => (i % 10 === 0 ? null : i * 1.1));
10+
const a: (number | null)[] = Array.from({ length: ROWS }, (_, i) =>
11+
i % 10 === 0 ? null : i * 1.1,
12+
);
1113
const b: (number | null)[] = Array.from({ length: ROWS }, (_, i) => (i % 7 === 0 ? null : i * 2.2));
1214
const df = DataFrame.fromColumns({ a, b });
1315

benchmarks/tsb/bench_series_fillna.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ const WARMUP = 5;
88
const ITERATIONS = 20;
99

1010
// Create series with every 5th value as null
11-
const data: (number | null)[] = Array.from({ length: ROWS }, (_, i) => (i % 5 === 0 ? null : i * 1.1));
11+
const data: (number | null)[] = Array.from({ length: ROWS }, (_, i) =>
12+
i % 5 === 0 ? null : i * 1.1,
13+
);
1214
const s = new Series({ data });
1315

1416
for (let i = 0; i < WARMUP; i++) {

benchmarks/tsb/bench_series_shift.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ function shiftSeries(series: Series<number>): Series<number | null> {
1919
const shifted: (number | null)[] = [null];
2020
for (let i = 0; i < vals.length - 1; i++) {
2121
const v = vals[i];
22-
if (v !== undefined) shifted.push(v);
22+
if (v !== undefined) {
23+
shifted.push(v);
24+
}
2325
}
2426
return new Series({ data: shifted });
2527
}

biome.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@
6969
"rules": {
7070
"nursery": {
7171
"noSecrets": "off"
72+
},
73+
"complexity": {
74+
"useLiteralKeys": "off"
75+
}
76+
}
77+
}
78+
},
79+
{
80+
"include": ["benchmarks/**"],
81+
"linter": {
82+
"rules": {
83+
"suspicious": {
84+
"noConsole": "off",
85+
"noConsoleLog": "off"
7286
}
7387
}
7488
}

src/core/api_types.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
* @module
2424
*/
2525

26-
import { Dtype } from "./dtype.ts";
2726
import type { DtypeName } from "../types.ts";
27+
import { Dtype } from "./dtype.ts";
2828

2929
// ─── internal helper ──────────────────────────────────────────────────────────
3030

@@ -95,14 +95,19 @@ export function isListLike(val: unknown): boolean {
9595
return false;
9696
}
9797
// Has Symbol.iterator and is not a plain number/boolean/bigint/symbol
98-
if (typeof val === "number" || typeof val === "boolean" || typeof val === "bigint" || typeof val === "symbol") {
98+
if (
99+
typeof val === "number" ||
100+
typeof val === "boolean" ||
101+
typeof val === "bigint" ||
102+
typeof val === "symbol"
103+
) {
99104
return false;
100105
}
101106
if (typeof val === "object" || typeof val === "function") {
102107
if (Symbol.iterator in (val as object)) {
103108
return true;
104109
}
105-
const len = (val as Record<string, unknown>)["length"];
110+
const len = (val as { length?: unknown }).length;
106111
if (typeof len === "number" && len >= 0 && Number.isInteger(len)) {
107112
return true;
108113
}
@@ -134,7 +139,7 @@ export function isArrayLike(val: unknown): boolean {
134139
if (typeof val !== "object" && typeof val !== "function") {
135140
return false;
136141
}
137-
const len = (val as Record<string, unknown>)["length"];
142+
const len = (val as { length?: unknown }).length;
138143
return typeof len === "number" && len >= 0 && Number.isInteger(len);
139144
}
140145

@@ -192,7 +197,7 @@ export function isIterator(val: unknown): boolean {
192197
if (typeof val !== "object" && typeof val !== "function") {
193198
return false;
194199
}
195-
return typeof (val as Record<string, unknown>)["next"] === "function";
200+
return typeof (val as { next?: unknown }).next === "function";
196201
}
197202

198203
/**

src/core/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ export { CategoricalAccessor } from "./cat_accessor.ts";
1515
export type { CatSeriesLike } from "./cat_accessor.ts";
1616
export { MultiIndex } from "./multi_index.ts";
1717
export type { MultiIndexOptions } from "./multi_index.ts";
18-
export { insertColumn, popColumn, reorderColumns, moveColumn, dataFrameFromPairs } from "./insert_pop.ts";
18+
export {
19+
insertColumn,
20+
popColumn,
21+
reorderColumns,
22+
moveColumn,
23+
dataFrameFromPairs,
24+
} from "./insert_pop.ts";
1925
export type { PopResult } from "./insert_pop.ts";
2026
export { toDictOriented, fromDictOriented } from "./to_from_dict.ts";
2127
export type {

src/core/insert_pop.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828

2929
import type { Label, Scalar } from "../types.ts";
30-
import { Index } from "./base-index.ts";
30+
import type { Index } from "./base-index.ts";
3131
import { DataFrame } from "./frame.ts";
3232
import { Series } from "./series.ts";
3333

src/core/pipe_apply.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ import type { Label, Scalar } from "../types.ts";
4545
export function pipe<A>(value: A): A;
4646
export function pipe<A, B>(value: A, fn1: (a: A) => B): B;
4747
export function pipe<A, B, C>(value: A, fn1: (a: A) => B, fn2: (b: B) => C): C;
48-
export function pipe<A, B, C, D>(
49-
value: A,
50-
fn1: (a: A) => B,
51-
fn2: (b: B) => C,
52-
fn3: (c: C) => D,
53-
): D;
48+
export function pipe<A, B, C, D>(value: A, fn1: (a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D): D;
5449
export function pipe<A, B, C, D, E>(
5550
value: A,
5651
fn1: (a: A) => B,
@@ -119,7 +114,11 @@ export function seriesApply(
119114
for (let i = 0; i < n; i++) {
120115
out[i] = fn(series.iat(i), series.index.at(i), i);
121116
}
122-
return new Series({ data: out, index: series.index, ...(series.name !== null ? { name: series.name } : {}) });
117+
return new Series({
118+
data: out,
119+
index: series.index,
120+
...(series.name !== null ? { name: series.name } : {}),
121+
});
123122
}
124123

125124
/**
@@ -141,7 +140,11 @@ export function seriesTransform(
141140
for (let i = 0; i < n; i++) {
142141
out[i] = fn(series.iat(i));
143142
}
144-
return new Series({ data: out, index: series.index, ...(series.name !== null ? { name: series.name } : {}) });
143+
return new Series({
144+
data: out,
145+
index: series.index,
146+
...(series.name !== null ? { name: series.name } : {}),
147+
});
145148
}
146149

147150
// ─── DataFrame apply ──────────────────────────────────────────────────────────
@@ -272,7 +275,11 @@ export function dataFrameTransform(
272275
*/
273276
export function dataFrameTransformRows(
274277
df: DataFrame,
275-
fn: (row: Readonly<Record<string, Scalar>>, rowLabel: Label, position: number) => Readonly<Record<string, Scalar>>,
278+
fn: (
279+
row: Readonly<Record<string, Scalar>>,
280+
rowLabel: Label,
281+
position: number,
282+
) => Readonly<Record<string, Scalar>>,
276283
): DataFrame {
277284
const colNames = df.columns.values as readonly string[];
278285
const rowLabels = df.index.values as readonly Label[];
@@ -290,7 +297,9 @@ export function dataFrameTransformRows(
290297
const rowOut = fn(rowIn, rowLabels[i] as Label, i);
291298
for (const c of colNames) {
292299
const colArr = colArrays.get(c);
293-
if (colArr === undefined) continue;
300+
if (colArr === undefined) {
301+
continue;
302+
}
294303
// use the transformed value if present, else keep original
295304
colArr[i] = c in rowOut ? (rowOut[c] as Scalar) : rowIn[c];
296305
}

src/core/to_from_dict.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,20 @@
2525
import type { Label, Scalar } from "../types.ts";
2626
import { Index } from "./base-index.ts";
2727
import { DataFrame } from "./frame.ts";
28-
import { Series } from "./series.ts";
28+
import type { Series } from "./series.ts";
2929

3030
// ─── public types ──────────────────────────────────────────────────────────────
3131

3232
/** 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";
3442

3543
/** Orient values supported by {@link fromDictOriented}. */
3644
export type FromDictOrient = "columns" | "index" | "split" | "tight";
@@ -78,17 +86,23 @@ function isDefaultRange(labels: readonly Label[]): boolean {
7886
* @param df Source DataFrame.
7987
* @param orient Output structure. Defaults to `"dict"`.
8088
*/
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>>;
8293
export function toDictOriented(df: DataFrame, orient: "list"): Record<string, Scalar[]>;
8394
export function toDictOriented(df: DataFrame, orient: "series"): Record<string, Series<Scalar>>;
8495
export function toDictOriented(df: DataFrame, orient: "split"): DictSplit;
8596
export function toDictOriented(df: DataFrame, orient: "tight"): DictTight;
8697
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>>;
88102
export function toDictOriented(
89103
df: DataFrame,
90104
orient: ToDictOrient = "dict",
91-
): Record<string, unknown> | unknown[] {
105+
): Record<string, unknown> | unknown[] | DictSplit | DictTight {
92106
const colNames = [...df.columns.values];
93107
const rowLabels = [...(df.index.values as Label[])];
94108
const nRows = df.index.size;
@@ -201,10 +215,7 @@ export function fromDictOriented(
201215
orient: "index",
202216
): DataFrame;
203217
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 {
208219
switch (orient) {
209220
case "columns": {
210221
const colsData = data as Record<string, readonly Scalar[]>;
@@ -266,8 +277,11 @@ function buildFromSplit(input: SplitInput): DataFrame {
266277
for (const row of data) {
267278
for (let j = 0; j < columns.length; j++) {
268279
const col = columns[j];
280+
if (col === undefined) {
281+
continue;
282+
}
269283
const arr = colArrays[col];
270-
if (col !== undefined && arr !== undefined) {
284+
if (arr !== undefined) {
271285
arr.push(row[j] ?? null);
272286
}
273287
}

src/index.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,22 @@ export type { ClipOptions, RoundOptions, DataFrameElemOptions } from "./stats/in
115115
export { valueCounts, dataFrameValueCounts } from "./stats/index.ts";
116116
export type { ValueCountsOptions, DataFrameValueCountsOptions } from "./stats/index.ts";
117117

118-
export { insertColumn, popColumn, reorderColumns, moveColumn, dataFrameFromPairs } from "./core/index.ts";
118+
export {
119+
insertColumn,
120+
popColumn,
121+
reorderColumns,
122+
moveColumn,
123+
dataFrameFromPairs,
124+
} from "./core/index.ts";
119125
export type { PopResult } from "./core/index.ts";
120126
export { toDictOriented, fromDictOriented } from "./core/index.ts";
121-
export type { ToDictOrient, FromDictOrient, DictSplit, DictTight, SplitInput } from "./core/index.ts";
127+
export type {
128+
ToDictOrient,
129+
FromDictOrient,
130+
DictSplit,
131+
DictTight,
132+
SplitInput,
133+
} from "./core/index.ts";
122134
export { wideToLong } from "./reshape/index.ts";
123135
export type { WideToLongOptions } from "./reshape/index.ts";
124136
export { cut, qcut } from "./stats/index.ts";
@@ -132,7 +144,16 @@ export type {
132144
SeriesWhereOptions,
133145
DataFrameWhereOptions,
134146
} from "./stats/index.ts";
135-
export { isna, notna, isnull, notnull, fillna, dropna, countna, countValid } from "./stats/index.ts";
147+
export {
148+
isna,
149+
notna,
150+
isnull,
151+
notnull,
152+
fillna,
153+
dropna,
154+
countna,
155+
countValid,
156+
} from "./stats/index.ts";
136157
export type { IsnaInput, FillnaOptions, DropnaOptions } from "./stats/index.ts";
137158
export {
138159
getAttrs,

0 commit comments

Comments
 (0)