Skip to content

Commit

Permalink
[CHORE]: move numeric out of daft-dsl and into daft-functions (#2857
Browse files Browse the repository at this point in the history
)
  • Loading branch information
universalmind303 authored Sep 23, 2024
1 parent b0f31e3 commit 134601b
Show file tree
Hide file tree
Showing 30 changed files with 1,015 additions and 1,002 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 27 additions & 25 deletions daft/daft/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1040,29 +1040,6 @@ class PySchema:
class PyExpr:
def alias(self, name: str) -> PyExpr: ...
def cast(self, dtype: PyDataType) -> PyExpr: ...
def ceil(self) -> PyExpr: ...
def floor(self) -> PyExpr: ...
def sign(self) -> PyExpr: ...
def round(self, decimal: int) -> PyExpr: ...
def sqrt(self) -> PyExpr: ...
def sin(self) -> PyExpr: ...
def cos(self) -> PyExpr: ...
def tan(self) -> PyExpr: ...
def cot(self) -> PyExpr: ...
def arcsin(self) -> PyExpr: ...
def arccos(self) -> PyExpr: ...
def arctan(self) -> PyExpr: ...
def arctan2(self, other: PyExpr) -> PyExpr: ...
def arctanh(self) -> PyExpr: ...
def arccosh(self) -> PyExpr: ...
def arcsinh(self) -> PyExpr: ...
def degrees(self) -> PyExpr: ...
def radians(self) -> PyExpr: ...
def log2(self) -> PyExpr: ...
def log10(self) -> PyExpr: ...
def log(self, base: float) -> PyExpr: ...
def ln(self) -> PyExpr: ...
def exp(self) -> PyExpr: ...
def if_else(self, if_true: PyExpr, if_false: PyExpr) -> PyExpr: ...
def count(self, mode: CountMode) -> PyExpr: ...
def sum(self) -> PyExpr: ...
Expand All @@ -1074,7 +1051,6 @@ class PyExpr:
def any_value(self, ignore_nulls: bool) -> PyExpr: ...
def agg_list(self) -> PyExpr: ...
def agg_concat(self) -> PyExpr: ...
def __abs__(self) -> PyExpr: ...
def __add__(self, other: PyExpr) -> PyExpr: ...
def __sub__(self, other: PyExpr) -> PyExpr: ...
def __mul__(self, other: PyExpr) -> PyExpr: ...
Expand Down Expand Up @@ -1217,9 +1193,35 @@ def minhash(
def sql(sql: str, catalog: PyCatalog, daft_planning_config: PyDaftPlanningConfig) -> LogicalPlanBuilder: ...
def sql_expr(sql: str) -> PyExpr: ...
def utf8_count_matches(expr: PyExpr, patterns: PyExpr, whole_words: bool, case_sensitive: bool) -> PyExpr: ...
def cbrt(expr: PyExpr) -> PyExpr: ...
def to_struct(inputs: list[PyExpr]) -> PyExpr: ...

# expr numeric ops
def abs(expr: PyExpr) -> PyExpr: ...
def cbrt(expr: PyExpr) -> PyExpr: ...
def ceil(expr: PyExpr) -> PyExpr: ...
def exp(expr: PyExpr) -> PyExpr: ...
def floor(expr: PyExpr) -> PyExpr: ...
def log2(expr: PyExpr) -> PyExpr: ...
def log10(expr: PyExpr) -> PyExpr: ...
def log(expr: PyExpr, base: float) -> PyExpr: ...
def ln(expr: PyExpr) -> PyExpr: ...
def round(expr: PyExpr, decimal: int) -> PyExpr: ...
def sign(expr: PyExpr) -> PyExpr: ...
def sqrt(expr: PyExpr) -> PyExpr: ...
def sin(expr: PyExpr) -> PyExpr: ...
def cos(expr: PyExpr) -> PyExpr: ...
def tan(expr: PyExpr) -> PyExpr: ...
def cot(expr: PyExpr) -> PyExpr: ...
def arcsin(expr: PyExpr) -> PyExpr: ...
def arccos(expr: PyExpr) -> PyExpr: ...
def arctan(expr: PyExpr) -> PyExpr: ...
def arctan2(expr: PyExpr, other: PyExpr) -> PyExpr: ...
def radians(expr: PyExpr) -> PyExpr: ...
def degrees(expr: PyExpr) -> PyExpr: ...
def arctanh(expr: PyExpr) -> PyExpr: ...
def arccosh(expr: PyExpr) -> PyExpr: ...
def arcsinh(expr: PyExpr) -> PyExpr: ...

# ---
# expr.image namespace
# ---
Expand Down
48 changes: 24 additions & 24 deletions daft/expressions/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def __abs__(self) -> Expression:

def abs(self) -> Expression:
"""Absolute of a numeric expression (``expr.abs()``)"""
return Expression._from_pyexpr(abs(self._expr))
return Expression._from_pyexpr(native.abs(self._expr))

def __add__(self, other: object) -> Expression:
"""Adds two numeric expressions or concatenates two string expressions (``e1 + e2``)"""
Expand Down Expand Up @@ -577,17 +577,17 @@ def cast(self, dtype: DataType) -> Expression:

def ceil(self) -> Expression:
"""The ceiling of a numeric expression (``expr.ceil()``)"""
expr = self._expr.ceil()
expr = native.ceil(self._expr)
return Expression._from_pyexpr(expr)

def floor(self) -> Expression:
"""The floor of a numeric expression (``expr.floor()``)"""
expr = self._expr.floor()
expr = native.floor(self._expr)
return Expression._from_pyexpr(expr)

def sign(self) -> Expression:
"""The sign of a numeric expression (``expr.sign()``)"""
expr = self._expr.sign()
expr = native.sign(self._expr)
return Expression._from_pyexpr(expr)

def round(self, decimals: int = 0) -> Expression:
Expand All @@ -597,12 +597,12 @@ def round(self, decimals: int = 0) -> Expression:
decimals: number of decimal places to round to. Defaults to 0.
"""
assert isinstance(decimals, int)
expr = self._expr.round(decimals)
expr = native.round(self._expr, decimals)
return Expression._from_pyexpr(expr)

def sqrt(self) -> Expression:
"""The square root of a numeric expression (``expr.sqrt()``)"""
expr = self._expr.sqrt()
expr = native.sqrt(self._expr)
return Expression._from_pyexpr(expr)

def cbrt(self) -> Expression:
Expand All @@ -611,37 +611,37 @@ def cbrt(self) -> Expression:

def sin(self) -> Expression:
"""The elementwise sine of a numeric expression (``expr.sin()``)"""
expr = self._expr.sin()
expr = native.sin(self._expr)
return Expression._from_pyexpr(expr)

def cos(self) -> Expression:
"""The elementwise cosine of a numeric expression (``expr.cos()``)"""
expr = self._expr.cos()
expr = native.cos(self._expr)
return Expression._from_pyexpr(expr)

def tan(self) -> Expression:
"""The elementwise tangent of a numeric expression (``expr.tan()``)"""
expr = self._expr.tan()
expr = native.tan(self._expr)
return Expression._from_pyexpr(expr)

def cot(self) -> Expression:
"""The elementwise cotangent of a numeric expression (``expr.cot()``)"""
expr = self._expr.cot()
expr = native.cot(self._expr)
return Expression._from_pyexpr(expr)

def arcsin(self) -> Expression:
"""The elementwise arc sine of a numeric expression (``expr.arcsin()``)"""
expr = self._expr.arcsin()
expr = native.arcsin(self._expr)
return Expression._from_pyexpr(expr)

def arccos(self) -> Expression:
"""The elementwise arc cosine of a numeric expression (``expr.arccos()``)"""
expr = self._expr.arccos()
expr = native.arccos(self._expr)
return Expression._from_pyexpr(expr)

def arctan(self) -> Expression:
"""The elementwise arc tangent of a numeric expression (``expr.arctan()``)"""
expr = self._expr.arctan()
expr = native.arctan(self._expr)
return Expression._from_pyexpr(expr)

def arctan2(self, other: Expression) -> Expression:
Expand All @@ -652,41 +652,41 @@ def arctan2(self, other: Expression) -> Expression:
* ``y >= 0``: ``(pi/2, pi]``
* ``y < 0``: ``(-pi, -pi/2)``"""
expr = Expression._to_expression(other)
return Expression._from_pyexpr(self._expr.arctan2(expr._expr))
return Expression._from_pyexpr(native.arctan2(self._expr, expr._expr))

def arctanh(self) -> Expression:
"""The elementwise inverse hyperbolic tangent of a numeric expression (``expr.arctanh()``)"""
expr = self._expr.arctanh()
expr = native.arctanh(self._expr)
return Expression._from_pyexpr(expr)

def arccosh(self) -> Expression:
"""The elementwise inverse hyperbolic cosine of a numeric expression (``expr.arccosh()``)"""
expr = self._expr.arccosh()
expr = native.arccosh(self._expr)
return Expression._from_pyexpr(expr)

def arcsinh(self) -> Expression:
"""The elementwise inverse hyperbolic sine of a numeric expression (``expr.arcsinh()``)"""
expr = self._expr.arcsinh()
expr = native.arcsinh(self._expr)
return Expression._from_pyexpr(expr)

def radians(self) -> Expression:
"""The elementwise radians of a numeric expression (``expr.radians()``)"""
expr = self._expr.radians()
expr = native.radians(self._expr)
return Expression._from_pyexpr(expr)

def degrees(self) -> Expression:
"""The elementwise degrees of a numeric expression (``expr.degrees()``)"""
expr = self._expr.degrees()
expr = native.degrees(self._expr)
return Expression._from_pyexpr(expr)

def log2(self) -> Expression:
"""The elementwise log base 2 of a numeric expression (``expr.log2()``)"""
expr = self._expr.log2()
expr = native.log2(self._expr)
return Expression._from_pyexpr(expr)

def log10(self) -> Expression:
"""The elementwise log base 10 of a numeric expression (``expr.log10()``)"""
expr = self._expr.log10()
expr = native.log10(self._expr)
return Expression._from_pyexpr(expr)

def log(self, base: float = math.e) -> Expression: # type: ignore
Expand All @@ -695,17 +695,17 @@ def log(self, base: float = math.e) -> Expression: # type: ignore
base: The base of the logarithm. Defaults to e.
"""
assert isinstance(base, (int, float)), f"base must be an int or float, but {type(base)} was provided."
expr = self._expr.log(float(base))
expr = native.log(self._expr, float(base))
return Expression._from_pyexpr(expr)

def ln(self) -> Expression:
"""The elementwise natural log of a numeric expression (``expr.ln()``)"""
expr = self._expr.ln()
expr = native.ln(self._expr)
return Expression._from_pyexpr(expr)

def exp(self) -> Expression:
"""The e^self of a numeric expression (``expr.exp()``)"""
expr = self._expr.exp()
expr = native.exp(self._expr)
return Expression._from_pyexpr(expr)

def bitwise_and(self, other: Expression) -> Expression:
Expand Down
7 changes: 2 additions & 5 deletions src/daft-dsl/src/functions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod map;
pub mod numeric;
pub mod partitioning;
pub mod scalar;
pub mod sketch;
Expand All @@ -17,8 +16,8 @@ pub use scalar::*;
use serde::{Deserialize, Serialize};

use self::{
map::MapExpr, numeric::NumericExpr, partitioning::PartitioningExpr, sketch::SketchExpr,
struct_::StructExpr, utf8::Utf8Expr,
map::MapExpr, partitioning::PartitioningExpr, sketch::SketchExpr, struct_::StructExpr,
utf8::Utf8Expr,
};
use crate::{Expr, ExprRef, Operator};

Expand All @@ -27,7 +26,6 @@ use python::PythonUDF;

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum FunctionExpr {
Numeric(NumericExpr),
Utf8(Utf8Expr),
Map(MapExpr),
Sketch(SketchExpr),
Expand All @@ -52,7 +50,6 @@ impl FunctionExpr {
fn get_evaluator(&self) -> &dyn FunctionEvaluator {
use FunctionExpr::*;
match self {
Numeric(expr) => expr.get_evaluator(),
Utf8(expr) => expr.get_evaluator(),
Map(expr) => expr.get_evaluator(),
Sketch(expr) => expr.get_evaluator(),
Expand Down
40 changes: 0 additions & 40 deletions src/daft-dsl/src/functions/numeric/abs.rs

This file was deleted.

40 changes: 0 additions & 40 deletions src/daft-dsl/src/functions/numeric/ceil.rs

This file was deleted.

Loading

0 comments on commit 134601b

Please sign in to comment.