TimeValue

TimeValue(arg)

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
delta Compute the number of parts between two times.
strftime Format a time according to format_str.
truncate Truncate the expression to a time expression in units of unit.

delta

delta(other, part)

Compute the number of parts between two times.

The order of operands matches standard subtraction

The second argument is subtracted from the first.

Parameters

Name Type Description Default
other datetime.time | Value[dt.Time] A time expression required
part Literal['hour', 'minute', 'second', 'millisecond', 'microsecond', 'nanosecond'] | Value[dt.String] The unit of time to compute the difference in required

Returns

Name Type Description
IntegerValue The number of parts between self and other

Examples

>>> import ibis
>>> ibis.options.interactive = True
>>> start = ibis.time("01:58:00")
>>> end = ibis.time("23:59:59")
>>> end.delta(start, unit="hour")

┌────┐
│ 22 │
└────┘
>>> data = '''tpep_pickup_datetime,tpep_dropoff_datetime
... 2016-02-01T00:23:56,2016-02-01T00:42:28
... 2016-02-01T00:12:14,2016-02-01T00:21:41
... 2016-02-01T00:43:24,2016-02-01T00:46:14
... 2016-02-01T00:55:11,2016-02-01T01:24:34
... 2016-02-01T00:11:13,2016-02-01T00:16:59'''
>>> with open("/tmp/triptimes.csv", "w") as f:
...     nbytes = f.write(data)  # nbytes is unused
>>> taxi = ibis.read_csv("/tmp/triptimes.csv")
>>> ride_duration = (
...     taxi.tpep_dropoff_datetime.time()
...     .delta(taxi.tpep_pickup_datetime.time(), unit="minute")
...     .name("ride_minutes")
... )
>>> ride_duration
┏━━━━━━━━━━━━━━┓
┃ ride_minutes ┃
┡━━━━━━━━━━━━━━┩
│ int64        │
├──────────────┤
│           19 │
│            9 │
│            3 │
│           29 │
│            5 │
└──────────────┘

strftime

strftime(format_str)

Format a time according to format_str.

Format string may depend on the backend, but we try to conform to ANSI strftime.

Parameters

Name Type Description Default
format_str str strftime format string required

Returns

Name Type Description
StringValue Formatted version of arg

truncate

truncate(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

Name Type Description
TimeValue self truncated to unit