You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
importpandasaspdimportpsycopg2fromsqlalchemyimportcreate_engineconn_string="postgresql://postgres:password@localhost/database"engine=create_engine(conn_string)
query="""select p.id as CustomerIdfrom table"""df=pd.read_sql(query, engine)
dtype_mappings= {
'CustomerId': int
}
df=df.astype(dtype_mappings)
Issue Description
When running the code we get the following error
.venv\lib\site-packages\pandas\core\generic.py", line 6605, in astype
raise KeyError(
KeyError: "Only a column name can be used for the key in a dtype mappings argument. 'CustomerId' not found in columns."
If we change the column name to all lower case, the code works.
Expected Behavior
pandas should support both upper and lower case for the column names
Installed Versions
Name: pandas
Version: 2.2.2
The text was updated successfully, but these errors were encountered:
Thanks for the report! Could you provide a reproducer without using read_sql?
Manually creating a DataFrame with a column named CustomerId and then running astype(dtype_mappings) works fine for me.
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
When running the code we get the following error
.venv\lib\site-packages\pandas\core\generic.py", line 6605, in astype
raise KeyError(
KeyError: "Only a column name can be used for the key in a dtype mappings argument. 'CustomerId' not found in columns."
If we change the column name to all lower case, the code works.
Expected Behavior
pandas should support both upper and lower case for the column names
Installed Versions
Name: pandas
Version: 2.2.2
The text was updated successfully, but these errors were encountered: