MySQL Forums
Forum List  »  Connector/Python

Re: Python mysql-connector doesn't handle numpy.nan
Posted by: Oscar Pacheco
Date: August 17, 2022 09:06AM

Hi Berel,

If possible, can you share a representative code snippet of how you are executing the insertions?

I myself have run a little experiment using a float numbers matrix (with some missing, a.k.a. numpy.nan). For testing purposes, I loop over each row (float number vector) and insert it into a table where its columns were defined as FLOAT at table creation time. For insertion, I used the cursor.execute() method.

When inserting matrix:
x1, y1, NaN
NaN, y2, z2

I get the following after fetching all from my dummy table using the connector:

[(x1, y1, None), (None, y2, z2)]

Finally, on the server side, it looks like

+----+------+-------+-------+
| id | x | y | z |
+----+------+-------+-------+
| 1 | x1 | y1 | NULL |
| 2 | NULL | y2 | z2 |
+----+------+-------+-------+

This result looks good to me.

Some notes:
- I am not using the fastest way of insertions since I want to prove the concept first.
- I understand there are many ways to do insertions, that's why I am curious to see yours.

Options: ReplyQuote


Subject
Written By
Posted
Re: Python mysql-connector doesn't handle numpy.nan
August 17, 2022 09:06AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.