Je ne peux pas le reproduire :
Oracle :
create table tab1 (id number, col1 number);
create table tab2 (id number, col2 varchar2(10));
insert into tab1 values(1, 10);
insert into tab1 values(2, 11);
insert into tab1 values(3,12);
insert into tab2 values(1,'aaa');
insert into tab2 values(2,'bbb');
insert into tab2 values(3,'ccc');
commit;
Python :
import pandas as pd
import cx_Oracle
from sqlalchemy import types, create_engine
usr = 'ora_user'
pwd = 'ora_pwd'
tns = """
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = test-rac-scan.wirecard.sys)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = <MY_SERVICE_NAME>.wirecard)
)
)
"""
qry = """
select a.col1,b.col2
from tab1 a, tab2 b
where a.id = b.id
"""
engine = create_engine('oracle+cx_oracle://%s:%s@%s' % (usr, pwd, tns))
df = pd.read_sql(qry, engine)
Résultat :
In [12]: df
Out[12]:
col1 col2
0 10 aaa
1 11 bbb
2 12 ccc
In [13]: df.dtypes
Out[13]:
col1 int64 # <-------- NOTE !
col2 object
dtype: object
Les versions du module :
In [14]: cx_Oracle.__version__
Out[14]: '5.3'
In [15]: pd.__version__
Out[15]: '0.19.2'
In [17]: sqlalchemy.__version__
Out[17]: '1.1.5'
UPDATE :
chaque colonne de DataFrame est un objet de type Pandas.Series - cela n'a rien à voir avec le dtype de la colonne :
In [50]: type(df['col1'])
Out[50]: pandas.core.series.Series
In [51]: type(df['col2'])
Out[51]: pandas.core.series.Series
In [52]: type(df)
Out[52]: pandas.core.frame.DataFrame
Si vous voulez vérifier un dtype
(analogue au type de données de la colonne Oracle) utiliser DataFrame.dtypes
attribut :
In [53]: df.dtypes
Out[53]:
col1 float64
col2 object
dtype: object