-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
ENH: sql support for NaN/NaT conversions #2754
Comments
Yes, I believe it expects Nones. I will post some code this weekend. |
I may in over my head here, actually, because performance is crucial. Would it helpful to consider #2717 ? |
this is actually tricky, you might need need to do some cython to get this fast... e.g. in pytables I had to pass a numpy rec-array because that is how it like it how are you passing, as a ndarray of dtype=object? (or rec-array)? list? |
try looking at this: pandas/io/pytables.py/AppenableTable.write_data (write a test table and break there) it uses this to write basically a numpy rec-array lib.pyx/create_hdf_rows_2d pretty sure you could do something similar this is a bit more complicated, because I use a mask to avoid writing completely empty rows (which is much more common in say writing a panel) |
see #3047 for a strategy of how u should deal with conversion to datetime64[ns] to make sure that u r returning NaT for missing values (this might actually be reasonably efficient too) |
you can also do this if u have the array directly wesm commented 10 minutes ago |
Actually I think we should try to fix this before 0.14. |
Overview of current status (see also tests added in #7100):
|
in hdf I do a translation on NaN to a string that can be user specified - (as can't store the NaN directly) I think that is a reasonable soln in case it can't be natively stored (or maybe always?) http://pandas-docs.github.io/pandas-docs-travis/io.html#string-columns (see nan_rep) |
But in theory it should be possible to store it natively in SQL I think, as there is the |
Their are 2 approaches you can use here: This is what i do in sqlalchemy (I am using a custom date-time type (not Timestamp but same idea)
alternatively, you can vectorize the conversion
|
@jorisvandenbossche ok...move to 0.14.1? |
yep |
UPDATE from @jorisvandenbossche:
Overview of current status writing nan values (see also tests added in #7100):
Unknown column 'nan' in 'field list'
(see also eg http://stackoverflow.com/questions/23353732/python-pandas-write-to-sql-with-nan-values)None
in sqliteu'NaN'
, which is not really what we wantNone
NaT
:'-001--1--1 -1:-1:-1.-00001'
not sure exactly what sql expects (Nones?) rather than np.nan (or NaT)
https://groups.google.com/forum/?fromgroups#!topic/pydata/lxhnFtuzvWQ
also provide pandas
datetime64[ns]
, instead ofdatetime/date
types#3532
The text was updated successfully, but these errors were encountered: