Skip to content

How to bulk load to oracle table when column has missing data NaN #249

@Newbee25

Description

@Newbee25

I'm trying to bulk load a dataframe into an oracle table. The following error occurs:

oracledb.exceptions.NotSupportedError: DPY-3013: unsupported Python type str for database type DB_TYPE_NUMBER

No error occurs when the records are inserted one by one.

Oracle table:

Column_Name Data_Type
Make VARCHAR2(20 BYTE)
Model VARCHAR2(20 BYTE)
Weight NUMBER
Year NUMBER(38,0)

Python Code

import pandas as pd
import numpy as np


data = {
  'Make': ['Honda', 'Toyota', 'BMW', 'Honda'],
  'Model': ['Civic', 'Camry', 'X5', 'Accord'],
  'Weight': [1020.25, np.NaN, 1235.37, 940.9],
  'Year': [2021, 2023, 2019, np.NaN]
}


df = pd.DataFrame(data)

print(df)
print(df.dtypes)

try:
    with db_connection.cursor() as cursor:
        
        cursor.executemany('insert into myTable values(:1, :2, :3, :4)', df.fillna('').values.tolist()) 
         
    db_connection.commit()
 
except Exception as error:
     print(error) 

Please note the floats NaN must be inserted as null values to the table.

I attempted df['Weight'].fillna(float('NaN'), inplace=True)and df['Year'].fillna(float('NaN'), inplace=True)
I also attempted to replace NaN with None.

It seems it is not recognizing None and NaN as valid types.
Is issue a possible bug?

I'm using the thick client mode and it is calling init_oracle_client()

Version

python-oracledb 1.4.1
Python 3.9.16

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions