Skip to Main Content

Data Science & Machine Learning

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

cx_OracleDB type error when saving timestamp value from Pandas

user-tczysAug 27 2023 — edited Aug 27 2023

Hi,

Wondering if anyone has any pointers with this problem. I'm loading up some data from a logging system using Python and am using Pandas DataFrames to store records before I push them to an OML AutonomousDB instance.

However, the oml_create method (using OML4PY) is throwing a KeyError and is not saving my data.

Here's the exception I'm getting:

KeyError: cx_Oracle.DbType DB_TYPE_TIMESTAMP_TZ

Here's a dump of a record with the timestamp column that is throwing an error:

df.loc[0]['evt_timestamp']

Timestamp('2023-07-30 03:25:25.748429+0000', tz='UTC')

type(df.loc[0]['evt_timestamp'])

<class 'pandas._libs.tslibs.timestamps.Timestamp'>

Here's a snippet of the code where I'm calling oml_create:

df = pd.DataFrame({
'userdfname':invalid_users,
'evt_timestamp':timestamps
})
oml_sshdata = None
try:
oml_sshdata = oml.create(df,table ="SSHLOGINDATA",dbtypes={'username':'VARCHAR2(4000)','evt_timestamp':'TIMESTAMP WITH TIME ZONE'})
except Exception as e:

Anyone got any pointers as to what might be causing that key error? Note that if I omit the dbtypes argument in oml_create I've seen that I get another exception that says that OML can't determine the datatype without me specifying it.

Thanks!

Comments

Post Details

Added on Aug 27 2023
0 comments
515 views