From c319ed3e36506e6e00498803a764bb8cc370cd63 Mon Sep 17 00:00:00 2001 From: Jim Crist-Harif Date: Wed, 18 Oct 2023 14:32:12 -0500 Subject: [PATCH] feat: improve generated column names for methods receiving intervals --- ibis/expr/operations/generic.py | 2 ++ ibis/expr/types/core.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ibis/expr/operations/generic.py b/ibis/expr/operations/generic.py index eb3398ef7cdf..b34f269c6daa 100644 --- a/ibis/expr/operations/generic.py +++ b/ibis/expr/operations/generic.py @@ -190,6 +190,8 @@ def __init__(self, value, dtype): @property def name(self): + if self.dtype.is_interval(): + return f"{self.value!r}{self.dtype.unit.short}" return repr(self.value) diff --git a/ibis/expr/types/core.py b/ibis/expr/types/core.py index 71633ab1b1f0..5e8246080de6 100644 --- a/ibis/expr/types/core.py +++ b/ibis/expr/types/core.py @@ -622,9 +622,9 @@ def _binop(op_class: type[ops.Binary], left: ir.Value, right: ir.Value) -> ir.Va >>> import ibis.expr.operations as ops >>> expr = _binop(ops.TimeAdd, ibis.time("01:00"), ibis.interval(hours=1)) >>> expr - TimeAdd(datetime.time(1, 0), 1): datetime.time(1, 0) + 1 h + TimeAdd(datetime.time(1, 0), 1h): datetime.time(1, 0) + 1 h >>> _binop(ops.TimeAdd, 1, ibis.interval(hours=1)) - TimeAdd(datetime.time(0, 0, 1), 1): datetime.time(0, 0, 1) + 1 h + TimeAdd(datetime.time(0, 0, 1), 1h): datetime.time(0, 0, 1) + 1 h """ try: node = op_class(left, right)