Skip to content

Commit 50c3132

Browse files
committed
feat(backends): kurtosis
1 parent 0b54fbb commit 50c3132

File tree

18 files changed

+128
-1
lines changed

18 files changed

+128
-1
lines changed

ibis/backends/polars/compiler.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,16 @@ def execute_std_var(op, **kw):
792792
return getattr(arg, method)(ddof=ddof)
793793

794794

795+
@translate.register(ops.Kurtosis)
796+
def execute_kurtosis(op, **kw):
797+
arg = translate(op.arg, **kw)
798+
799+
if (where := op.where) is not None:
800+
arg = arg.filter(translate(where, **kw))
801+
802+
return arg.kurtosis(bias=op.how == "pop")
803+
804+
795805
@translate.register(ops.Mode)
796806
def execute_mode(op, **kw):
797807
arg = translate(op.arg, **kw)

ibis/backends/sql/compilers/base.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import operator
88
import string
99
from functools import partial, reduce
10-
from typing import TYPE_CHECKING, Any, Callable, ClassVar
10+
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Literal
1111

1212
import sqlglot as sg
1313
import sqlglot.expressions as sge
@@ -1059,6 +1059,15 @@ def visit_CountDistinctStar(self, op, *, arg, where):
10591059
def visit_CountStar(self, op, *, arg, where):
10601060
return self.agg.count(STAR, where=where)
10611061

1062+
def visit_Kurtosis(self, op, *, arg, where, how: Literal["sample", "pop"]):
1063+
if op.arg.dtype.is_boolean():
1064+
arg = self.cast(arg, dt.int32)
1065+
1066+
if how == "sample":
1067+
return self.agg.kurtosis(arg, where=where)
1068+
else:
1069+
return self.agg.kurtosis_pop(arg, where=where)
1070+
10621071
def visit_Sum(self, op, *, arg, where):
10631072
if op.arg.dtype.is_boolean():
10641073
arg = self.cast(arg, dt.int32)

ibis/backends/sql/compilers/clickhouse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class ClickHouseCompiler(SQLGlotCompiler):
5555
ops.StringToDate,
5656
ops.StringToTime,
5757
ops.Levenshtein,
58+
ops.Kurtosis,
5859
)
5960

6061
SIMPLE_OPS = {

ibis/backends/sql/compilers/datafusion.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class DataFusionCompiler(SQLGlotCompiler):
4444
ops.StringToDate,
4545
ops.StringToTimestamp,
4646
ops.StringToTime,
47+
# in theory possible via
48+
# https://github.com/datafusion-contrib/datafusion-functions-extra but
49+
# not clear how to use that library from Python
50+
ops.Kurtosis,
4751
)
4852

4953
SIMPLE_OPS = {

ibis/backends/sql/compilers/druid.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class DruidCompiler(SQLGlotCompiler):
4747
ops.IntervalFromInteger,
4848
ops.IsNan,
4949
ops.IsInf,
50+
ops.Kurtosis,
5051
ops.Levenshtein,
5152
ops.Median,
5253
ops.RandomScalar,

ibis/backends/sql/compilers/exasol.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class ExasolCompiler(SQLGlotCompiler):
5858
ops.IntervalFromInteger,
5959
ops.IsInf,
6060
ops.IsNan,
61+
ops.Kurtosis,
6162
ops.Levenshtein,
6263
ops.MultiQuantile,
6364
ops.RandomUUID,

ibis/backends/sql/compilers/flink.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class FlinkCompiler(SQLGlotCompiler):
9090
ops.RowID,
9191
ops.Translate,
9292
ops.StringToTime,
93+
ops.Kurtosis,
9394
)
9495

9596
SIMPLE_OPS = {

ibis/backends/sql/compilers/impala.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class ImpalaCompiler(SQLGlotCompiler):
5757
ops.TimestampBucket,
5858
ops.TimestampDelta,
5959
ops.Unnest,
60+
ops.Kurtosis,
6061
)
6162

6263
SIMPLE_OPS = {

ibis/backends/sql/compilers/mssql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class MSSQLCompiler(SQLGlotCompiler):
100100
ops.Covariance,
101101
ops.CountDistinctStar,
102102
ops.DateDiff,
103+
ops.Kurtosis,
103104
ops.IntervalAdd,
104105
ops.IntervalSubtract,
105106
ops.IntervalMultiply,

ibis/backends/sql/compilers/mysql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def POS_INF(self):
7272
ops.ArgMax,
7373
ops.ArgMin,
7474
ops.Covariance,
75+
ops.Kurtosis,
7576
ops.Levenshtein,
7677
ops.Median,
7778
ops.Mode,

0 commit comments

Comments
 (0)