-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Timestamp sub second resolution not supported with MySQL #7938
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
This is a limitation of MySQL (see http://dev.mysql.com/doc/refman/5.0/en/datetime.html). I personally think we should not do anything about this (users of MySQL should be aware of that / live with the limitation or circumvent it themselves if needed). But we can certainly add a warning to the docs. And maybe it would be possible to add a UserWarning when there are sub-second data that will be discarded? (or maybe that would be too costly to check?) @danielballan @mangecoeur @hayd @jreback What do you think? |
silly question, is this a printing issue with the db? (e.g. can you have the db dump the actual values)? |
No, quote from the link of mysql docs:
So the information is lost when the values are stored in the database. |
see also http://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html microseconds seems to be supported by MySQL (but not nanoseconds). Do you really think that datetime64 shouldn't be stored as integer ? if you consider this is a bad idea why not using |
Yes, I don't think that is a good idea (but try to convince me otherwise!) My reasoning:
|
For compatibility with other systems, I don't think datetime64 should be stored as integers. MySQL users would expect dates to be dates. Pandas users can convert their datetime64 columns to ints or strings before writing to the db. As @jorisvandenbossche says, there are too many reasonable ways to do this: we don't want to guess. I think there's a case for making pandas warn. The performance cost is a concern. Not sure how I feel about this. FYI, I remember seeing 2-3 years ago that the feature request page for robust support of fractional seconds in MySQL is more than 10 years old. |
I understand that UserWarnings come with a computational time cost... so I can live without that. I would like to keep dataframe with datetime64 but I would like to be able to "tell" to SQLAlchemy how to manage them with database storage. Is there an API for that (a kind of converter to overload and to pass to |
@femtotrader I think that should be possible, take a look here: http://docs.sqlalchemy.org/en/rel_0_9/core/types.html#custom-types, you can overwrite existing or define new types in the way they are handled by sqlalchemy. That is maybe also a way to solve the datetime problem with mysql-connector and pymysql. If you get it to work, can you post it here? We maybe can add it as an example to the docs. |
A possible way to check:
Would this be acceptable as a performance loss? |
@jorisvandenbossche still relevant? (if so pls assign to milestone), otherwise close |
Seems like this is a MySQL limitation and there's not a clear action on the pandas side. Going to close for now, but happy to reopen if I misunderstood |
Hello,
Timestamp sub second resolution doesn't seem to be supported with mysqldb.
See:
doesn't raise any error but when I queried database I noticed that I have only second resolution timestamp (no microsecond, in fact no fractional seconds).
Maybe storing
datetime64
into integer value could be the most portable solution over database, driver...The text was updated successfully, but these errors were encountered: