Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
### Push this to Postgresql ###
create table product(
product_id varchar(255) primary key not null,
price varchar(255) not null,
gender varchar(255),
name varchar(255) not null,
recommendable boolean not null,
is_active boolean not null,
fk_event_number integer references event(event_number) not null
);
### call pandas function ###
df_products_db = pd.read_sql_table("product",engine.connect())
print(df_products_db.dtypes) # returns 4 object data types, should be strings
Issue Description
When using pandas.read_sql_table() to request data from a (in my case) localhost postgres database, the data types returned are different then the data types specified in the postgresql enviorment
Expected Behavior
Data types should be strings (as they are varchar(255) in the database), but return as object types
Installed Versions
Comment From: asishm
object
is the default data type for strings, so this is expected until the default changes.
Comment From: Alper2022
Where could i change this default?
Comment From: phofl
You can use convert_dtypes or set the dtype_backend option starting with pandas 2.0