How do I convert numpy NaN objects to SQL nulls?

Поиск
Список
Период
Сортировка
От Gregory Arenius
Тема How do I convert numpy NaN objects to SQL nulls?
Дата
Msg-id CAMPu647QNGY+HpJVEBGKEzk4h37uDDW0ovWaZuiHC1oqvAkvJA@mail.gmail.com
обсуждение исходный текст
Ответы Re: How do I convert numpy NaN objects to SQL nulls?  (Adrian Klaver <adrian.klaver@aklaver.com>)
Re: How do I convert numpy NaN objects to SQL nulls?  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
Список psycopg
have a Pandas dataframe that I'm inserting into an SQL database. I'm using Psycopg2 directly to talk to the database, not SQLAlchemy, so I can't use Pandas built in to_sql functions. Almost everything works as expected except for the fact that numpy np.NaN values get converted to text as NaN and inserted into the database. They really should be treated as SQL null values.

So, I'm trying to make a custom adapter to convert np.NaN to SQL null but everything I've tried results in the same NaN strings being inserted in the database.

The code I'm currently trying is:

def adapt_nans(null):   a = adapt(None).getquoted()   return AsIs(a)

register_adapter(np.NaN, adapt_nans)

I've tried a number of variations along this theme but haven't had any luck.

Cheers,

Greg

В списке psycopg по дате отправления:

Предыдущее
От: Jonathan Rogers
Дата:
Сообщение: Re: ISQLQuote vs. str subclass
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: How do I convert numpy NaN objects to SQL nulls?