Skip to content

Commit cea8ed8

Browse files
NickCrewscpcloud
authored andcommitted
docs: add concepts doc on casting
1 parent 75c88fd commit cea8ed8

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/concepts/casting.qmd

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Casting between datatypes
2+
3+
This is a compendium of how ibis treats casts between various datatypes.
4+
This often follows the semantics of the underlying backend, but
5+
sometimes ibis adds some glue code in between to make things consistent
6+
between backends.
7+
8+
## Timestamps
9+
10+
When casting from numeric types such as integers, decimals, and floating values,
11+
timestamps treated as the number of seconds since the epoch.
12+
So `0` is `1970-01-01 00:00:00` and `1` is `1970-01-01 00:00:01`.
13+
Subsecond fractions are supported when possible.
14+
Casting to numeric types is not implemented for most backends,
15+
but should be the inverse of the above.
16+
For example, `ibis.literal('1970-01-01 00:00:01').cast(int)` should return `1`.
17+
If the timestamp has subsecond resolution, timestamp is truncated to the second.
18+
19+
When casting to/from strings, the format is `YYYY-MM-DD HH:MM:SS[.SSSSSSSSS]`.
20+
We haven't gotten to defining behavior with timezones in the string yet.
21+
Some backends may work, but others may not.
22+
PRs to implement this are welcomed!
23+
24+
## Intervals
25+
26+
When casting to/from numeric types such as integers, decimals, and floating values,
27+
intervals are treated as the number of the particular interval.
28+
For example `ibis.literal(123).cast("interval('s')")` results in
29+
an interval of 123 seconds.
30+
Casting the other direction from intervals to integers is not currently supported.

0 commit comments

Comments
 (0)