Time Field Weird Behavior
ArtemM opened this issue · 2 comments
Hello!
There is a chance that I'm doing something wrong (I'm new both to Python and Coda) but I experience a pretty strange issue when I have a time column in coda and try to get values via API.
Here is the coda doc:
https://coda.io/d/Time-Issue_dfKm5iMR4yL
And python snippet:
from codaio import Coda, Document
import pandas as pd
coda = Coda('xxx')
doc = Document('fKm5iMR4yL', coda=coda)
doc.list_tables()
table = doc.get_table('grid-CrrXtSG3kN')
mt = [t["Measure Time"] for t in table.to_dict()]
print(mt)
And output:
['1899-12-29T21:57:56.000-08:00', '1899-12-29T22:27:56.000-08:00', '1899-12-30T00:57:56.000-08:00']
Note that time is 4s off.
If I add that 4s and convert with
import numpy as np
from datetime import timedelta, datetime, date
import datetime as dt
import dateutil.parser
import pytz
for input_row in table.to_dict():
mt = input_row["Measure Time"]
print(mt)
tz = pytz.timezone("Europe/Kiev")
t = dateutil.parser.isoparse(mt).astimezone(tz)
time_shift = datetime.combine(date.min, t.time()) - datetime.min
time_shift_in_hours = time_shift + dt.timedelta(seconds=4)
print(time_shift_in_hours)
Then the result is "fine":
1899-12-29T21:57:56.000-08:00
8:00:00
1899-12-29T22:27:56.000-08:00
8:30:00
1899-12-30T00:57:56.000-08:00
11:00:00
So:
- I guess time in dates should be exact one (not 4s behind)
- Possibly optimal to use some python time object rather than minimum date + time?
- Assuming there is an issue here, is my workaround (adding 4s as above) fine as a monkey patch or I'm somehow digging a hole here?
Hi @ArtemM,
Sorry for the late reply. It looks like you found a bug in Coda's API. Here's the response you get from raw API:
{
"id": "i-6cTHvsspvY",
"type": "row",
"href": "https://coda.io/apis/v1/docs/fKm5iMR4yL/tables/grid-CrrXtSG3kN/rows/i-6cTHvsspvY",
"name": "9:57 PM",
"index": 0,
"createdAt": "2021-04-24T06:34:45.663Z",
"updatedAt": "2021-04-24T07:48:31.485Z",
"browserLink": "https://coda.io/d/_dfKm5iMR4yL#_tugrid-CrrXtSG3kN/_rui-6cTHvsspvY",
"values": {
"c-1IHXiCIclS": "1899-12-29T21:57:56.000-08:00"
}
The value is off by 4 seconds in the API response, which is not surprising since codaio doesn't do anything with your data without you. And it definetely doesn't offset time by 4 s.
I will try reporting it to the Coda team.
Another minor inconvenience is that the column type is TIME, but the returned value is DateTime, with year set to 1899. Which can be handled, but really it would be better to just get "08:00" instead.
Also the returned format doesn't match the description in the getColumn endpoint:
{
"id": "c-1IHXiCIclS",
"type": "column",
"name": "Measure Time",
"href": "https://coda.io/apis/v1/docs/fKm5iMR4yL/tables/grid-CrrXtSG3kN/columns/c-1IHXiCIclS",
"display": true,
"format": {
"format": "h:mm A",
"type": "time",
"isArray": false
}
}
So the returned format should be "9:00 AM" or something like that, but definetely not a full datetime string.
Got a response from the support team. It seems the 4s error is due to incorrect data entry with past rounding. They'll work on fixing the format discrepancy. Issue closed.