diff --git a/ibis/backends/sql/compiler.py b/ibis/backends/sql/compiler.py index e0d86918eec4c..157a4220156ed 100644 --- a/ibis/backends/sql/compiler.py +++ b/ibis/backends/sql/compiler.py @@ -787,7 +787,7 @@ def visit_DayOfWeekIndex(self, op, *, arg): return (self.f.dayofweek(arg) + 6) % 7 def visit_IsoDayOfWeekIndex(self, op, *, arg): - return self.f.dayofweek(arg) + return (self.f.dayofweek(arg) + 6) % 7+1 def visit_DayOfWeekName(self, op, *, arg): @@ -799,15 +799,6 @@ def visit_DayOfWeekName(self, op, *, arg): ifs=list(itertools.starmap(self.if_, enumerate(calendar.day_name))), ) - def visit_DayOfWeekName(self, op, *, arg): - # day of week number is 0-indexed - # Sunday == 0 - # Saturday == 6 - return sge.Case( - this=self.f.dayofweek(arg), - ifs=list(itertools.starmap(self.if_, enumerate(calendar.day_name))), - ) - def visit_IntervalFromInteger(self, op, *, arg, unit): return sge.Interval( this=sge.convert(arg), unit=sge.Var(this=unit.singular.upper()) diff --git a/ibis/expr/operations/temporal.py b/ibis/expr/operations/temporal.py index 315667ee416ce..2148a7e0c4773 100644 --- a/ibis/expr/operations/temporal.py +++ b/ibis/expr/operations/temporal.py @@ -164,12 +164,23 @@ class DayOfWeekIndex(Unary): dtype = dt.int16 +@public +class IsoDayOfWeekIndex(Unary): + arg: Value[dt.Date | dt.Timestamp] + + dtype = dt.int16 + @public class DayOfWeekName(Unary): arg: Value[dt.Date | dt.Timestamp] dtype = dt.string +@public +class IsoDayOfWeekName(Unary): + arg: Value[dt.Date | dt.Timestamp] + + dtype = dt.string @public diff --git a/ibis/expr/types/temporal.py b/ibis/expr/types/temporal.py index dd673b5ef6d97..d7d48796c139d 100644 --- a/ibis/expr/types/temporal.py +++ b/ibis/expr/types/temporal.py @@ -988,3 +988,24 @@ def full_name(self): The name of the day of the week """ return ops.DayOfWeekName(self._expr).to_expr() + + + def iso_index(self): + """Get the index of the day of the week in iso-format (1=Monday, 7=Sunday). + + Returns + ------- + IntegerValue + The index of the day of the week in iso-format (1=Monday, 7=Sunday). + """ + return ops.IsoDayOfWeekIndex(self._expr).to_expr() + + def iso_full_name(self): + """Get the name of the day of the week. + + Returns + ------- + StringValue + The name of the day of the week + """ + return ops.IsoDayOfWeekName(self._expr).to_expr() \ No newline at end of file