I'm just trying to send to sybase ASE some float data containing nan, the expected result being a NULL in the database. The pandas version is 1.3.5, and python Python 3.8.12, and sqlalchemy 1.4.28 .
Creation of the table:
create table test(head VARCHAR(20) NOT NULL, val FLOAT NULL, primary key(head))
Creation of the dataframe:
df = pd.DataFrame({"head":["A","B","C"], "val":[1.2,np.nan,42.0]}) #math.nan gets the same result
And now the code that crashes :
df.to_sql("test",
con = engine,
if_exists="replace",
index=False,
dtype={'head': db.types.VARCHAR(20), 'val': db.types.FLOAT},
chunksize=1)
the error message:
[SAP][ASE ODBC Driver][Adaptive Server Enterprise]Implicit conversion from datatype 'VARCHAR' to 'FLOAT' is not allowed. Use the CONVERT function to run this query.
Any idea about what's happening? Everywhere I looked, it seemed like this ought to work like a charm!