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