-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Sqlachemy raises when writing write timedelta64 columns to sqlite. #6921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
it looks like there isn't a timedelta/interval type in sqlite, so we can't really support serialization/deserialization. (given that there's no metadata to be found) I'd support raising here. |
The reason you get this error is the following I think: we say to sqlalchemy that it is a timedelta (wich maps to But I agree this is a bit difficult to support. And we have also to test this for other flavors, as I actually think this will not work for any (timedelta's are totally untested at the moment). Eg postgresql has a timedelta type, but at the moment this will give the same error I think. Maybe we should just disallow timedelta's for now, or explicitely save them to sql as ints and raise a warning saying this? |
Can we at least add a warning? |
Convert to integer and add warning? Or drop column and warning? |
I vote for convert to integer and warn -- if we can't solve it properly. On Friday, April 25, 2014, Joris Van den Bossche [email protected]
|
Here's some options (and
string conversion
|
@jreback The string conversion, is this always non-ambiguous? And not subject to change? (eg how the string output of timedelta looks like has recently changed? #5701) Because if we convert it to a string, it should be some kind of 'standard' way of formatting a timedelta I think.
But easiest seems to do a conversion to int. I suppose we should always use the same frequency base, so always using |
it is always non ambiguous however the format I picked is not necessarily standard per se if I can use a timedelata object maybe do that biggest issue is reverse inference so if sqlalchemy does have a timedelta type I would just do that (and defer to 0.14.1 if needed) |
From sqlalchmey docs: 'the value is stored as a date which is relative to the “epoch” (Jan. 1, 1970).' (http://docs.sqlalchemy.org/en/rel_0_9/core/types.html#sqlalchemy.types.Interval). So also not ideal I think, and difficult to reverse infer the data type. Eg for mysql (which has no native timedelta type), for a timedelta of one day, you will get the datetime |
If you know its a timedelta, then this is very easy to reverse
just
|
yes, but the problem is: we don't know it is a timedelta, as it is just stored as a datetime. |
isn't their a column type? (isn't that that what sqlalchemy returns to you?) if not that IS a big problem; storing as int/string have the same problem. you could add a |
@jreback yes there will be a column type, but this will be of type
I would for now certainly raise a UserWarning. For conversion to int/string, I would also tend to convert to int (although @jreback you prefered string?), as this seems less surprising than a datetime somwhere in the '70s. But then what timebase: ns? (as this is how it is stored in pandas) |
+1 for storing as ints. Another reason: you can do numerical operations on them in the database, also true for the flavors that support a full-fledged timedelta column type. Nanosecond timebase makes sense to me -- it would be hard to justify a different choice. |
all sounds good to me |
ok, I will put up a fix |
Maybe we can work around this. At least it should raise informatively.
The full traceback is in this gist.
Using a
sqlite3.Connection
(legacy-style) allows you to write and read.The data comes back as
int64
type. There is no clean way around this, no obvious way to tell that these sqlite3 integers are actually timedeltas. We could store timedeltas as strings, like datetimes. But I'm not necessarily in favor of that approach.The text was updated successfully, but these errors were encountered: