Skip to content

Commit

Permalink
refactor(temporal): remove unnecessary Temporal* classes
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and gforsyth committed Nov 13, 2023
1 parent 7dbbeb2 commit d3bcf73
Showing 1 changed file with 64 additions and 44 deletions.
108 changes: 64 additions & 44 deletions ibis/expr/types/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,6 @@
import ibis.expr.types as ir


@public
class TemporalValue(Value):
def strftime(self, format_str: str) -> ir.StringValue:
"""Format timestamp according to `format_str`.
Format string may depend on the backend, but we try to conform to ANSI
`strftime`.
Parameters
----------
format_str
`strftime` format string
Returns
-------
StringValue
Formatted version of `arg`
"""
return ops.Strftime(self, format_str).to_expr()


@public
class TemporalScalar(Scalar, TemporalValue):
pass


@public
class TemporalColumn(Column, TemporalValue):
pass


class _DateComponentMixin:
"""Temporal expressions that have a date component."""

Expand Down Expand Up @@ -176,11 +145,26 @@ def between(


@public
class TimeValue(_TimeComponentMixin, TemporalValue):
def truncate(
self,
unit: Literal["h", "m", "s", "ms", "us", "ns"],
) -> TimeValue:
class TimeValue(_TimeComponentMixin, Value):
def strftime(self, format_str: str) -> ir.StringValue:
"""Format a time according to `format_str`.
Format string may depend on the backend, but we try to conform to ANSI
`strftime`.
Parameters
----------
format_str
`strftime` format string
Returns
-------
StringValue
Formatted version of `arg`
"""
return ops.Strftime(self, format_str).to_expr()

def truncate(self, unit: Literal["h", "m", "s", "ms", "us", "ns"]) -> TimeValue:
"""Truncate the expression to a time expression in units of `unit`.
Commonly used for time series resampling.
Expand Down Expand Up @@ -322,17 +306,35 @@ def delta(


@public
class TimeScalar(TemporalScalar, TimeValue):
class TimeScalar(Scalar, TimeValue):
pass


@public
class TimeColumn(TemporalColumn, TimeValue):
class TimeColumn(Column, TimeValue):
pass


@public
class DateValue(TemporalValue, _DateComponentMixin):
class DateValue(Value, _DateComponentMixin):
def strftime(self, format_str: str) -> ir.StringValue:
"""Format a date according to `format_str`.
Format string may depend on the backend, but we try to conform to ANSI
`strftime`.
Parameters
----------
format_str
`strftime` format string
Returns
-------
StringValue
Formatted version of `arg`
"""
return ops.Strftime(self, format_str).to_expr()

def truncate(self, unit: Literal["Y", "Q", "M", "W", "D"]) -> DateValue:
"""Truncate date expression to units of `unit`.
Expand Down Expand Up @@ -465,17 +467,35 @@ def delta(


@public
class DateScalar(TemporalScalar, DateValue):
class DateScalar(Scalar, DateValue):
pass


@public
class DateColumn(TemporalColumn, DateValue):
class DateColumn(Column, DateValue):
pass


@public
class TimestampValue(_DateComponentMixin, _TimeComponentMixin, TemporalValue):
class TimestampValue(_DateComponentMixin, _TimeComponentMixin, Value):
def strftime(self, format_str: str) -> ir.StringValue:
"""Format a timestamp according to `format_str`.
Format string may depend on the backend, but we try to conform to ANSI
`strftime`.
Parameters
----------
format_str
`strftime` format string
Returns
-------
StringValue
Formatted version of `arg`
"""
return ops.Strftime(self, format_str).to_expr()

def truncate(
self,
unit: Literal["Y", "Q", "M", "W", "D", "h", "m", "s", "ms", "us", "ns"],
Expand Down Expand Up @@ -760,12 +780,12 @@ def delta(


@public
class TimestampScalar(TemporalScalar, TimestampValue):
class TimestampScalar(Scalar, TimestampValue):
pass


@public
class TimestampColumn(TemporalColumn, TimestampValue):
class TimestampColumn(Column, TimestampValue):
pass


Expand Down

0 comments on commit d3bcf73

Please sign in to comment.