Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit ef4637e

Browse files
cleanup unneeded round op
1 parent 648518f commit ef4637e

File tree

5 files changed

+4
-35
lines changed

5 files changed

+4
-35
lines changed

bigframes/core/compile/ibis_compiler/scalar_op_registry.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,11 +1029,6 @@ def timedelta_floor_op_impl(x: ibis_types.NumericValue):
10291029
return ibis_api.case().when(x > 0, x.floor()).else_(x.ceil()).end()
10301030

10311031

1032-
@scalar_op_compiler.register_unary_op(ops.timedelta_round_op)
1033-
def timedelta_round_op_impl(x: ibis_types.NumericValue):
1034-
return ibis_api.case().when(x > 0, x.floor()).else_(x.ceil()).end()
1035-
1036-
10371032
@scalar_op_compiler.register_unary_op(ops.RemoteFunctionOp, pass_op=True)
10381033
def remote_function_op_impl(x: ibis_types.Value, op: ops.RemoteFunctionOp):
10391034
udf_sig = op.function_def.signature

bigframes/core/compile/sqlglot/expressions/timedelta_ops.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ def _(expr: TypedExpr) -> sge.Expression:
3030
return sge.Floor(this=expr.expr)
3131

3232

33-
@register_unary_op(ops.timedelta_round_op)
34-
def _(expr: TypedExpr) -> sge.Expression:
35-
return sge.Round(this=expr.expr).cast()
36-
37-
3833
@register_unary_op(ops.ToTimedeltaOp, pass_op=True)
3934
def _(expr: TypedExpr, op: ops.ToTimedeltaOp) -> sge.Expression:
4035
value = expr.expr

bigframes/core/rewrite/timedeltas.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ def _rewrite_mul_op(left: _TypedExpr, right: _TypedExpr) -> _TypedExpr:
189189
result = _TypedExpr.create_op_expr(ops.mul_op, left, right)
190190

191191
if left.dtype == dtypes.TIMEDELTA_DTYPE and dtypes.is_numeric(right.dtype):
192-
return _TypedExpr.create_op_expr(ops.timedelta_round_op, result)
192+
return _TypedExpr.create_op_expr(ops.timedelta_floor_op, result)
193193
if dtypes.is_numeric(left.dtype) and right.dtype == dtypes.TIMEDELTA_DTYPE:
194-
return _TypedExpr.create_op_expr(ops.timedelta_round_op, result)
194+
return _TypedExpr.create_op_expr(ops.timedelta_floor_op, result)
195195

196196
return result
197197

@@ -200,15 +200,15 @@ def _rewrite_div_op(left: _TypedExpr, right: _TypedExpr) -> _TypedExpr:
200200
result = _TypedExpr.create_op_expr(ops.div_op, left, right)
201201

202202
if left.dtype == dtypes.TIMEDELTA_DTYPE and dtypes.is_numeric(right.dtype):
203-
return _TypedExpr.create_op_expr(ops.timedelta_round_op, result)
203+
return _TypedExpr.create_op_expr(ops.timedelta_floor_op, result)
204204

205205
return result
206206

207207

208208
def _rewrite_floordiv_op(left: _TypedExpr, right: _TypedExpr) -> _TypedExpr:
209209
if left.dtype == dtypes.TIMEDELTA_DTYPE and dtypes.is_numeric(right.dtype):
210210
return _TypedExpr.create_op_expr(
211-
ops.timedelta_round_op, _TypedExpr.create_op_expr(ops.div_op, left, right)
211+
ops.timedelta_floor_op, _TypedExpr.create_op_expr(ops.div_op, left, right)
212212
)
213213

214214
return _TypedExpr.create_op_expr(ops.floordiv_op, left, right)

bigframes/operations/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@
224224
date_add_op,
225225
date_sub_op,
226226
timedelta_floor_op,
227-
timedelta_round_op,
228227
timestamp_add_op,
229228
timestamp_sub_op,
230229
ToTimedeltaOp,
@@ -309,7 +308,6 @@
309308
"date_add_op",
310309
"date_sub_op",
311310
"timedelta_floor_op",
312-
"timedelta_round_op",
313311
"timestamp_add_op",
314312
"timestamp_sub_op",
315313
"ToTimedeltaOp",

bigframes/operations/timedelta_ops.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,6 @@ def output_type(self, *input_types: dtypes.ExpressionType) -> dtypes.ExpressionT
5454
timedelta_floor_op = TimedeltaFloorOp()
5555

5656

57-
@dataclasses.dataclass(frozen=True)
58-
class TimedeltaRoundOp(base_ops.UnaryOp):
59-
"""Rounds the numeric value to the nearest integer and use it to represent a timedelta.
60-
61-
This operator is only meant to be used during expression tree rewrites. Do not use it anywhere else!
62-
"""
63-
64-
name: typing.ClassVar[str] = "timedelta_round"
65-
66-
def output_type(self, *input_types: dtypes.ExpressionType) -> dtypes.ExpressionType:
67-
input_type = input_types[0]
68-
if dtypes.is_numeric(input_type) or input_type == dtypes.TIMEDELTA_DTYPE:
69-
return dtypes.TIMEDELTA_DTYPE
70-
raise TypeError(f"unsupported type: {input_type}")
71-
72-
73-
timedelta_round_op = TimedeltaRoundOp()
74-
75-
7657
@dataclasses.dataclass(frozen=True)
7758
class TimestampAddOp(base_ops.BinaryOp):
7859
name: typing.ClassVar[str] = "timestamp_add"

0 commit comments

Comments
 (0)