Skip to content

Commit

Permalink
Adding arc functions (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bidek56 authored Apr 22, 2024
1 parent 181cf47 commit d1ae96f
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 1 deletion.
18 changes: 18 additions & 0 deletions __tests__/expr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ describe("expr", () => {
const actual = df().filter(col("bools").eq(false).and(col("int").eq(3)));
expect(actual.height).toStrictEqual(1);
});
test("arccos", () => {
const df = pl.DataFrame({ a: [1, 2] });
const expected = pl.DataFrame({ arccos: [0.0, Number.NaN] });
const actual = df.select(col("a").arccos().as("arccos"));
expect(actual).toFrameEqual(expected);
});
test("arcsin", () => {
const df = pl.DataFrame({ a: [1, 2] });
const expected = pl.DataFrame({ arcsin: [1.570796, Number.NaN] });
const actual = df.select(col("a").arcsin().round(6).as("arcsin"));
expect(actual).toFrameEqual(expected);
});
test("arcyan", () => {
const df = pl.DataFrame({ a: [1, 2] });
const expected = pl.DataFrame({ arctan: [0.785398, 1.107149] });
const actual = df.select(col("a").arctan().round(6).as("arctan"));
expect(actual).toFrameEqual(expected);
});
test("argMax", () => {
const actual = df().select(col("int").argMax()).row(0)[0];
expect(actual).toStrictEqual(2);
Expand Down
127 changes: 126 additions & 1 deletion polars/lazy/expr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,114 @@ export interface Expr
*/
alias(name: string): Expr;
and(other: any): Expr;
/**
* Compute the element-wise value for the inverse cosine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [0.0]})
>>> df.select(pl.col("a").acrcos())
shape: (1, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 1.570796 │
└──────────┘
* ```
*/
arccos(): Expr;
/**
* Compute the element-wise value for the inverse hyperbolic cosine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").acrcosh())
shape: (1, 1)
┌─────┐
│ a │
│ --- │
│ f64 │
╞═════╡
│ 0.0 │
└─────┘
* ```
*/
arccosh(): Expr;
/**
* Compute the element-wise value for the inverse sine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").acrsin())
shape: (1, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 1.570796 │
└──────────┘
* ```
*/
arcsin(): Expr;
/**
* Compute the element-wise value for the inverse hyperbolic sine.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").acrsinh())
shape: (1, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 0.881374 │
└──────────┘
* ```
*/
arcsinh(): Expr;
/**
* Compute the element-wise value for the inverse tangent.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").arctan())
shape: (1, 1)
┌──────────┐
│ a │
│ --- │
│ f64 │
╞══════════╡
│ 0.785398 │
└──────────┘
* ```
*/
arctan(): Expr;
/**
* Compute the element-wise value for the inverse hyperbolic tangent.
* @returns Expression of data type :class:`Float64`.
* @example
* ```
>>> const df = pl.DataFrame({"a": [1.0]})
>>> df.select(pl.col("a").arctanh())
shape: (1, 1)
┌─────┐
│ a │
│ --- │
│ f64 │
╞═════╡
│ inf │
└─────┘
* ```
*/
arctanh(): Expr;
/** Get the index of the maximal value. */
argMax(): Expr;
/** Get the index of the minimal value. */
Expand Down Expand Up @@ -881,9 +989,26 @@ export const _Expr = (_expr: any): Expr => {
},
and(other) {
const expr = (exprToLitOrExpr(other, false) as any).inner();

return _Expr(_expr.and(expr));
},
arccos() {
return _Expr(_expr.arccos());
},
arccosh() {
return _Expr(_expr.arccosh());
},
arcsin() {
return _Expr(_expr.arcsin());
},
arcsinh() {
return _Expr(_expr.arcsinh());
},
arctan() {
return _Expr(_expr.arctan());
},
arctanh() {
return _Expr(_expr.arctanh());
},
argMax() {
return _Expr(_expr.argMax());
},
Expand Down

0 comments on commit d1ae96f

Please sign in to comment.