Skip to content

Commit

Permalink
Linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bidek56 committed Jan 4, 2024
1 parent 7dcfedc commit 4eedf68
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 254 deletions.
55 changes: 25 additions & 30 deletions __tests__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ expect.extend({
message: () => "series matches",
pass: true,
};
} else {
return {
message: () => `
}
return {
message: () => `
Expected:
>>${expected}
Received:
>>${actual}`,
pass: false,
};
}
pass: false,
};
},
toSeriesEqual(actual, expected) {
const pass = actual.seriesEqual(expected);
Expand All @@ -27,16 +26,15 @@ Received:
message: () => "series matches",
pass: true,
};
} else {
return {
message: () => `
}
return {
message: () => `
Expected:
>>${expected}
Received:
>>${actual}`,
pass: false,
};
}
pass: false,
};
},
toFrameEqual(actual, expected, nullEqual?) {
const pass = actual.frameEqual(expected, nullEqual);
Expand All @@ -45,16 +43,15 @@ Received:
message: () => "dataframes match",
pass: true,
};
} else {
return {
message: () => `
}
return {
message: () => `
Expected:
>>${expected}
Received:
>>${actual}`,
pass: false,
};
}
pass: false,
};
},
toFrameStrictEqual(actual, expected) {
const frameEq = actual.frameEqual(expected);
Expand All @@ -64,16 +61,15 @@ Received:
message: () => "dataframes match",
pass: true,
};
} else {
return {
message: () => `
}
return {
message: () => `
Expected:
>>${expected}
Received:
>>${actual}`,
pass: false,
};
}
pass: false,
};
},
toFrameEqualIgnoringOrder(act: pl.DataFrame, exp: pl.DataFrame) {
const actual = act.sort(act.columns.sort());
Expand All @@ -84,16 +80,15 @@ Received:
message: () => "dataframes match",
pass: true,
};
} else {
return {
message: () => `
}
return {
message: () => `
Expected:
>>${expected}
Received:
>>${actual}`,
pass: false,
};
}
pass: false,
};
},
});

Expand Down
49 changes: 18 additions & 31 deletions polars/dataframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1708,9 +1708,8 @@ export interface DataFrame
function prepareOtherArg(anyValue: any): Series {
if (Series.isSeries(anyValue)) {
return anyValue;
} else {
return Series([anyValue]) as Series;
}
return Series([anyValue]) as Series;
}

function map(df: DataFrame, fn: (...args: any[]) => any[]) {
Expand Down Expand Up @@ -1841,9 +1840,8 @@ export const _DataFrame = (_df: any): DataFrame => {
df.getColumns().map((s) => {
if (s.isNumeric() || s.isBoolean()) {
return s.cast(DataType.Float64);
} else {
return s;
}
return s;
}),
);
};
Expand Down Expand Up @@ -1877,9 +1875,8 @@ export const _DataFrame = (_df: any): DataFrame => {
dropNulls(...subset) {
if (subset.length) {
return wrap("dropNulls", subset.flat(2));
} else {
return wrap("dropNulls");
}
return wrap("dropNulls");
},
distinct(opts: any = false, subset?, keep = "first") {
return this.unique(opts, subset);
Expand Down Expand Up @@ -2037,9 +2034,8 @@ export const _DataFrame = (_df: any): DataFrame => {
max(axis = 0) {
if (axis === 1) {
return _Series(_df.hmax() as any) as any;
} else {
return wrap("max");
}
return wrap("max");
},
mean(axis = 0, nullStrategy = "ignore") {
if (axis === 1) {
Expand All @@ -2057,9 +2053,8 @@ export const _DataFrame = (_df: any): DataFrame => {
min(axis = 0) {
if (axis === 1) {
return _Series(_df.hmin() as any) as any;
} else {
return wrap("min");
}
return wrap("min");
},
nChunks() {
return _df.nChunks();
Expand Down Expand Up @@ -2168,28 +2163,25 @@ export const _DataFrame = (_df: any): DataFrame => {
false,
seed,
);
} else {
throw new TypeError("must specify either 'frac' or 'n'");
}
throw new TypeError("must specify either 'frac' or 'n'");
},
select(...selection) {
const hasExpr = selection.flat().some((s) => Expr.isExpr(s));
if (hasExpr) {
return _DataFrame(_df).lazy().select(selection).collectSync();
} else {
return wrap("select", columnOrColumnsStrict(selection as any));
}
return wrap("select", columnOrColumnsStrict(selection as any));
},
shift: (opt) => wrap("shift", opt?.periods ?? opt),
shiftAndFill(n: any, fillValue?: number | undefined) {
if (typeof n === "number" && fillValue) {
return _DataFrame(_df).lazy().shiftAndFill(n, fillValue).collectSync();
} else {
return _DataFrame(_df)
.lazy()
.shiftAndFill(n.n, n.fillValue)
.collectSync();
}
return _DataFrame(_df)
.lazy()
.shiftAndFill(n.n, n.fillValue)
.collectSync();
},
shrinkToFit(inPlace: any = false): any {
if (inPlace) {
Expand Down Expand Up @@ -2408,9 +2400,8 @@ export const _DataFrame = (_df: any): DataFrame => {
}
if (!options?.columnNames) {
return wrap("transpose", keep_names_as, undefined);
} else {
return wrap("transpose", keep_names_as, options.columnNames);
}
return wrap("transpose", keep_names_as, options.columnNames);
},
unnest(names) {
names = Array.isArray(names) ? names : [names];
Expand All @@ -2428,28 +2419,25 @@ export const _DataFrame = (_df: any): DataFrame => {
withColumn(column: Series | Expr) {
if (Series.isSeries(column)) {
return wrap("withColumn", column.inner());
} else {
return this.withColumns(column);
}
return this.withColumns(column);
},
withColumns(...columns: (Expr | Series)[]) {
if (isSeriesArray(columns)) {
return columns.reduce(
(acc, curr) => acc.withColumn(curr),
_DataFrame(_df),
);
} else {
return this.lazy()
.withColumns(columns)
.collectSync({ noOptimization: true, stringCache: false });
}
return this.lazy()
.withColumns(columns)
.collectSync({ noOptimization: true, stringCache: false });
},
withColumnRenamed(opt, replacement?) {
if (typeof opt === "string") {
return this.rename({ [opt]: replacement });
} else {
return this.rename({ [opt.existing]: opt.replacement });
}
return this.rename({ [opt.existing]: opt.replacement });
},
withRowCount(name = "row_nr") {
return wrap("withRowCount", name);
Expand Down Expand Up @@ -2477,9 +2465,8 @@ export const _DataFrame = (_df: any): DataFrame => {
}
if (typeof prop !== "symbol" && !Number.isNaN(Number(prop))) {
return target.row(Number(prop));
} else {
return Reflect.get(target, prop, receiver);
}
return Reflect.get(target, prop, receiver);
},
set(target: DataFrame, prop, receiver) {
if (Series.isSeries(receiver)) {
Expand Down
19 changes: 7 additions & 12 deletions polars/datatypes/datatype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ export abstract class DataType {
toString() {
if (this.inner) {
return `${this.identity}(${this.variant}(${this.inner}))`;
} else {
return `${this.identity}(${this.variant})`;
}
return `${this.identity}(${this.variant})`;
}
toJSON() {
const inner = (this as any).inner;
Expand All @@ -136,11 +135,10 @@ export abstract class DataType {
[this.variant]: inner[0],
},
};
} else {
return {
[this.identity]: this.variant,
};
}
return {
[this.identity]: this.variant,
};
}
[Symbol.for("nodejs.util.inspect.custom")]() {
return this.toJSON();
Expand Down Expand Up @@ -186,9 +184,8 @@ class _Datetime extends DataType {
this.timeUnit === (other as _Datetime).timeUnit &&
this.timeZone === (other as _Datetime).timeZone
);
} else {
return false;
}
return false;
}
}

Expand All @@ -202,9 +199,8 @@ class _List extends DataType {
override equals(other: DataType): boolean {
if (other.variant === this.variant) {
return this.inner[0].equals((other as _List).inner[0]);
} else {
return false;
}
return false;
}
}

Expand Down Expand Up @@ -237,9 +233,8 @@ class _Struct extends DataType {
return otherfld.name === fld.name && otherfld.dtype.equals(fld.dtype);
})
.every((value) => value);
} else {
return false;
}
return false;
}
override toJSON() {
return {
Expand Down
6 changes: 3 additions & 3 deletions polars/datatypes/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export namespace Field {
export function from(nameOrObj, dtype?: DataType): Field {
if (typeof nameOrObj === "string" && dtype) {
return new Field(nameOrObj, dtype);
} else if (Array.isArray(nameOrObj)) {
}
if (Array.isArray(nameOrObj)) {
return new Field(nameOrObj[0], nameOrObj[1]);
} else {
return new Field(nameOrObj.name, nameOrObj.dtype);
}
return new Field(nameOrObj.name, nameOrObj.dtype);
}
}
22 changes: 10 additions & 12 deletions polars/groupby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,8 @@ export function _GroupBy(df: any, by: string[], maintainOrder = false) {
if (typeof opts === "string") {
if (valuesCol) {
return pivot({ pivotCol: opts, valuesCol });
} else {
throw new Error("must specify both pivotCol and valuesCol");
}
throw new Error("must specify both pivotCol and valuesCol");
}

return PivotOps(df, by, opts.pivotCol, opts.valuesCol);
Expand All @@ -191,17 +190,16 @@ export function _GroupBy(df: any, by: string[], maintainOrder = false) {
.groupBy(by, maintainOrder)
.agg(...aggs)
.collectSync({ noOptimization: true });
} else {
const pairs = Object.entries(aggs[0]).flatMap(([key, values]) => {
return [values].flat(2).map((v) => col(key)[v as any]());
});

return _DataFrame(df)
.lazy()
.groupBy(by, maintainOrder)
.agg(...pairs)
.collectSync({ noOptimization: true });
}
const pairs = Object.entries(aggs[0]).flatMap(([key, values]) => {
return [values].flat(2).map((v) => col(key)[v as any]());
});

return _DataFrame(df)
.lazy()
.groupBy(by, maintainOrder)
.agg(...pairs)
.collectSync({ noOptimization: true });
};

return Object.seal({
Expand Down
Loading

0 comments on commit 4eedf68

Please sign in to comment.