Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: pandas dataframe column definition or mapping does not cater for upper case values. #59045

Open
2 of 3 tasks
c8-devops opened this issue Jun 18, 2024 · 1 comment
Open
2 of 3 tasks
Labels
Astype Bug Needs Info Clarification about behavior needed to assess issue

Comments

@c8-devops
Copy link

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

import pandas as pd
import psycopg2
from sqlalchemy import create_engine

conn_string = "postgresql://postgres:password@localhost/database"
engine = create_engine(conn_string)

query = """
select 
	p.id as CustomerId
from 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

@c8-devops c8-devops added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 18, 2024
@Aloqeely
Copy link
Member

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.

@Aloqeely Aloqeely added Needs Info Clarification about behavior needed to assess issue Astype and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Astype Bug Needs Info Clarification about behavior needed to assess issue
Projects
None yet
Development

No branches or pull requests

2 participants