Skip to content

Commit d1ae96f

Browse files
authored
Adding arc functions (pola-rs#200)
1 parent 181cf47 commit d1ae96f

File tree

2 files changed

+144
-1
lines changed

2 files changed

+144
-1
lines changed

__tests__/expr.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,24 @@ describe("expr", () => {
4444
const actual = df().filter(col("bools").eq(false).and(col("int").eq(3)));
4545
expect(actual.height).toStrictEqual(1);
4646
});
47+
test("arccos", () => {
48+
const df = pl.DataFrame({ a: [1, 2] });
49+
const expected = pl.DataFrame({ arccos: [0.0, Number.NaN] });
50+
const actual = df.select(col("a").arccos().as("arccos"));
51+
expect(actual).toFrameEqual(expected);
52+
});
53+
test("arcsin", () => {
54+
const df = pl.DataFrame({ a: [1, 2] });
55+
const expected = pl.DataFrame({ arcsin: [1.570796, Number.NaN] });
56+
const actual = df.select(col("a").arcsin().round(6).as("arcsin"));
57+
expect(actual).toFrameEqual(expected);
58+
});
59+
test("arcyan", () => {
60+
const df = pl.DataFrame({ a: [1, 2] });
61+
const expected = pl.DataFrame({ arctan: [0.785398, 1.107149] });
62+
const actual = df.select(col("a").arctan().round(6).as("arctan"));
63+
expect(actual).toFrameEqual(expected);
64+
});
4765
test("argMax", () => {
4866
const actual = df().select(col("int").argMax()).row(0)[0];
4967
expect(actual).toStrictEqual(2);

polars/lazy/expr/index.ts

+126-1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,114 @@ export interface Expr
143143
*/
144144
alias(name: string): Expr;
145145
and(other: any): Expr;
146+
/**
147+
* Compute the element-wise value for the inverse cosine.
148+
* @returns Expression of data type :class:`Float64`.
149+
* @example
150+
* ```
151+
>>> const df = pl.DataFrame({"a": [0.0]})
152+
>>> df.select(pl.col("a").acrcos())
153+
shape: (1, 1)
154+
┌──────────┐
155+
│ a │
156+
│ --- │
157+
│ f64 │
158+
╞══════════╡
159+
│ 1.570796 │
160+
└──────────┘
161+
* ```
162+
*/
163+
arccos(): Expr;
164+
/**
165+
* Compute the element-wise value for the inverse hyperbolic cosine.
166+
* @returns Expression of data type :class:`Float64`.
167+
* @example
168+
* ```
169+
>>> const df = pl.DataFrame({"a": [1.0]})
170+
>>> df.select(pl.col("a").acrcosh())
171+
shape: (1, 1)
172+
┌─────┐
173+
│ a │
174+
│ --- │
175+
│ f64 │
176+
╞═════╡
177+
│ 0.0 │
178+
└─────┘
179+
* ```
180+
*/
181+
arccosh(): Expr;
182+
/**
183+
* Compute the element-wise value for the inverse sine.
184+
* @returns Expression of data type :class:`Float64`.
185+
* @example
186+
* ```
187+
>>> const df = pl.DataFrame({"a": [1.0]})
188+
>>> df.select(pl.col("a").acrsin())
189+
shape: (1, 1)
190+
┌──────────┐
191+
│ a │
192+
│ --- │
193+
│ f64 │
194+
╞══════════╡
195+
│ 1.570796 │
196+
└──────────┘
197+
* ```
198+
*/
199+
arcsin(): Expr;
200+
/**
201+
* Compute the element-wise value for the inverse hyperbolic sine.
202+
* @returns Expression of data type :class:`Float64`.
203+
* @example
204+
* ```
205+
>>> const df = pl.DataFrame({"a": [1.0]})
206+
>>> df.select(pl.col("a").acrsinh())
207+
shape: (1, 1)
208+
┌──────────┐
209+
│ a │
210+
│ --- │
211+
│ f64 │
212+
╞══════════╡
213+
│ 0.881374 │
214+
└──────────┘
215+
* ```
216+
*/
217+
arcsinh(): Expr;
218+
/**
219+
* Compute the element-wise value for the inverse tangent.
220+
* @returns Expression of data type :class:`Float64`.
221+
* @example
222+
* ```
223+
>>> const df = pl.DataFrame({"a": [1.0]})
224+
>>> df.select(pl.col("a").arctan())
225+
shape: (1, 1)
226+
┌──────────┐
227+
│ a │
228+
│ --- │
229+
│ f64 │
230+
╞══════════╡
231+
│ 0.785398 │
232+
└──────────┘
233+
* ```
234+
*/
235+
arctan(): Expr;
236+
/**
237+
* Compute the element-wise value for the inverse hyperbolic tangent.
238+
* @returns Expression of data type :class:`Float64`.
239+
* @example
240+
* ```
241+
>>> const df = pl.DataFrame({"a": [1.0]})
242+
>>> df.select(pl.col("a").arctanh())
243+
shape: (1, 1)
244+
┌─────┐
245+
│ a │
246+
│ --- │
247+
│ f64 │
248+
╞═════╡
249+
│ inf │
250+
└─────┘
251+
* ```
252+
*/
253+
arctanh(): Expr;
146254
/** Get the index of the maximal value. */
147255
argMax(): Expr;
148256
/** Get the index of the minimal value. */
@@ -881,9 +989,26 @@ export const _Expr = (_expr: any): Expr => {
881989
},
882990
and(other) {
883991
const expr = (exprToLitOrExpr(other, false) as any).inner();
884-
885992
return _Expr(_expr.and(expr));
886993
},
994+
arccos() {
995+
return _Expr(_expr.arccos());
996+
},
997+
arccosh() {
998+
return _Expr(_expr.arccosh());
999+
},
1000+
arcsin() {
1001+
return _Expr(_expr.arcsin());
1002+
},
1003+
arcsinh() {
1004+
return _Expr(_expr.arcsinh());
1005+
},
1006+
arctan() {
1007+
return _Expr(_expr.arctan());
1008+
},
1009+
arctanh() {
1010+
return _Expr(_expr.arctanh());
1011+
},
8871012
argMax() {
8881013
return _Expr(_expr.argMax());
8891014
},

0 commit comments

Comments
 (0)