Temporal expressions

Dates, times, timestamps and intervals.

TimestampValue

expr.types.temporal.TimestampValue()

Attributes

Name Description
add Add an interval to a timestamp.
radd Add an interval to a timestamp.
sub Subtract a timestamp or an interval from a timestamp.

Methods

Name Description
date Return the date component of the expression.
truncate Truncate timestamp expression to units of unit.

date

date(self)

Return the date component of the expression.

Returns

Type Description
DateValue The date component of self

truncate

truncate(self, unit)

Truncate timestamp expression to units of unit.

Parameters

Name Type Description Default
unit Literal[‘Y’, ‘Q’, ‘M’, ‘W’, ‘D’, ‘h’, ‘m’, ‘s’, ‘ms’, ‘us’, ‘ns’] Unit to truncate to required

Returns

Type Description
TimestampValue Truncated timestamp expression

DateValue

expr.types.temporal.DateValue()

Attributes

Name Description
add Add an interval to a date.
radd Add an interval to a date.
sub Subtract a date or an interval from a date.

Methods

Name Description
truncate Truncate date expression to units of unit.

truncate

truncate(self, unit)

Truncate date expression to units of unit.

Parameters

Name Type Description Default
unit Literal[‘Y’, ‘Q’, ‘M’, ‘W’, ‘D’] Unit to truncate arg to required

Returns

Type Description
DateValue Truncated date value expression

TimeValue

expr.types.temporal.TimeValue()

Attributes

Name Description
add Add an interval to a time expression.
radd Add an interval to a time expression.
sub Subtract a time or an interval from a time expression.

Methods

Name Description
truncate Truncate the expression to a time expression in units of unit.

truncate

truncate(self, unit)

Truncate the expression to a time expression in units of unit.

Commonly used for time series resampling.

Parameters

Name Type Description Default
unit Literal[‘h’, ‘m’, ‘s’, ‘ms’, ‘us’, ‘ns’] The unit to truncate to required

Returns

Type Description
TimeValue self truncated to unit

IntervalValue

expr.types.temporal.IntervalValue()

Attributes

Name Description
days Extract the number of days from an interval.
hours Extract the number of hours from an interval.
microseconds Extract the number of microseconds from an interval.
milliseconds Extract the number of milliseconds from an interval.
minutes Extract the number of minutes from an interval.
months Extract the number of months from an interval.
nanoseconds Extract the number of nanoseconds from an interval.
quarters Extract the number of quarters from an interval.
seconds Extract the number of seconds from an interval.
weeks Extract the number of weeks from an interval.
years Extract the number of years from an interval.

Methods

Name Description
negate Negate an interval expression.
to_unit Convert this interval to units of target_unit.

negate

negate(self)

Negate an interval expression.

Returns

Type Description
IntervalValue A negated interval value expression

to_unit

to_unit(self, target_unit)

Convert this interval to units of target_unit.

DayOfWeek

expr.types.temporal.DayOfWeek(self, expr)

A namespace of methods for extracting day of week information.

Methods

Name Description
full_name Get the name of the day of the week.
index Get the index of the day of the week.

full_name

full_name(self)

Get the name of the day of the week.

Returns

Type Description
StringValue The name of the day of the week

index

index(self)

Get the index of the day of the week.

Ibis follows the pandas convention for day numbering: Monday = 0 and Sunday = 6.

Returns

Type Description
IntegerValue The index of the day of the week.

now

now()

Return an expression that will compute the current timestamp.

Returns

Type Description
TimestampScalar An expression representing the current timestamp.

date

date(value, *args)

Return a date literal if value is coercible to a date.

Parameters

Name Type Description Default
value Date string, datetime object or numeric value required
args Month and day if value is a year ()

Returns

Type Description
DateScalar A date expression

time

time(value, *args)

Return a time literal if value is coercible to a time.

Parameters

Name Type Description Default
value Time string required
args Minutes, seconds if value is an hour ()

Returns

Type Description
TimeScalar A time expression

Examples

>>> import ibis
>>> ibis.options.interactive = True
>>> ibis.time("00:00:00")

datetime.time(0, 0)
>>> ibis.time(12, 15, 30)

datetime.time(12, 15, 30)

timestamp

timestamp(value, *args, timezone=None)

Return a timestamp literal if value is coercible to a timestamp.

Parameters

Name Type Description Default
value Timestamp string, datetime object or numeric value required
args Additional arguments if value is numeric ()
timezone str | None Timezone name None

Returns

Type Description
TimestampScalar A timestamp expression

Examples

>>> import ibis
>>> ibis.options.interactive = True
>>> ibis.timestamp("2021-01-01 00:00:00")

Timestamp('2021-01-01 00:00:00')

interval

interval(value=None, unit='s', *, years=None, quarters=None, months=None, weeks=None, days=None, hours=None, minutes=None, seconds=None, milliseconds=None, microseconds=None, nanoseconds=None)

Return an interval literal expression.

Parameters

Name Type Description Default
value int | datetime.timedelta | None Interval value. None
unit str Unit of value 's'
years int | None Number of years None
quarters int | None Number of quarters None
months int | None Number of months None
weeks int | None Number of weeks None
days int | None Number of days None
hours int | None Number of hours None
minutes int | None Number of minutes None
seconds int | None Number of seconds None
milliseconds int | None Number of milliseconds None
microseconds int | None Number of microseconds None
nanoseconds int | None Number of nanoseconds None

Returns

Type Description
IntervalScalar An interval expression
Back to top