Skip to content

BUG: to_sql works only for strings #61385

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

Open
2 of 3 tasks
pranav-ds opened this issue May 1, 2025 · 1 comment
Open
2 of 3 tasks

BUG: to_sql works only for strings #61385

pranav-ds opened this issue May 1, 2025 · 1 comment
Labels
Bug IO SQL to_sql, read_sql, read_sql_query Needs Info Clarification about behavior needed to assess issue

Comments

@pranav-ds
Copy link

pranav-ds commented May 1, 2025

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 panda as pd
from sqlalchemy.types import DOUBLE

data = # Panda Datafrme with timestamp, double and string along with different column types.
column_types_filtered_data = {col: DOUBLE() for col in data.columns}
data.to_sql(..., dtype=column_types_filtered_data)

Issue Description

For any type other than str this block in pandas.io.sql will fail.

for col, my_type in dtype.items():
                if not isinstance(my_type, str):
                    raise ValueError(f"{col} ({my_type}) not a string")

Expected Behavior

Different datatypes should be supported.

Installed Versions

pandas==2.2.3

@pranav-ds pranav-ds added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 1, 2025
@rhshadrach
Copy link
Member

The block in question should only be hit when pandas falls back to sqlite3. What kind of connection are you supplying?

@rhshadrach rhshadrach added IO SQL to_sql, read_sql, read_sql_query Needs Info Clarification about behavior needed to assess issue and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO SQL to_sql, read_sql, read_sql_query Needs Info Clarification about behavior needed to assess issue
Projects
None yet
Development

No branches or pull requests

2 participants