Skip to content
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

FIX sql handling of timedelta64 columns (GH6921) #7076

Merged

Conversation

jorisvandenbossche
Copy link
Member

Closes #6921

Converting to an int was actually also how it was now with sqlite DBAPI fallback (as timedelta64 is subclass of integer), so this solution is also backwards compatible and consistent between sqlalchemy and fallback mode.

@jorisvandenbossche
Copy link
Member Author

@danielballan @jreback

@jreback
Copy link
Contributor

jreback commented May 8, 2014

don't you need to explicity cast before you write to the db itself? (e.g. doing s.astype('int64'), essentially converting it to an integer column)

@jreback jreback added the SQL label May 8, 2014
@jreback jreback added this to the 0.14.0 milestone May 8, 2014
@jorisvandenbossche
Copy link
Member Author

Not really necessary, as it is an int subclass, and in the sql write code np.asscalar is used to convert the numpy scalars to python types:

In [29]: np.asscalar(np.timedelta64(10000, 'ns'))
Out[29]: 10000L

@jorisvandenbossche
Copy link
Member Author

Ah, and it seems I have to skip the tests for older numpy versions. Updated.

@jreback
Copy link
Contributor

jreback commented May 8, 2014

looks good

@jreback
Copy link
Contributor

jreback commented May 8, 2014

def put this as a warning in the docs though

@jorisvandenbossche
Copy link
Member Author

OK, added a note in the docs.

jorisvandenbossche added a commit that referenced this pull request May 11, 2014
FIX sql handling of timedelta64 columns (GH6921)
@jorisvandenbossche jorisvandenbossche merged commit 33c66bf into pandas-dev:master May 11, 2014
@jorisvandenbossche jorisvandenbossche deleted the sql-timedelta branch May 11, 2014 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO SQL to_sql, read_sql, read_sql_query Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sqlachemy raises when writing write timedelta64 columns to sqlite.
2 participants