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

to_sql method returns "AttributeError: 'Engine' object has no attribute 'cursor'" whenever pandas>2.0.0 #11671

Open
fabclmnt opened this issue Jan 14, 2025 · 0 comments
Labels
needs triage Needs a response from a contributor

Comments

@fabclmnt
Copy link

Describe the issue:
Whenever using DASK to_sql method (https://docs.dask.org/en/stable/generated/dask.dataframe.to_sql.html), the following error is shown
image

This error is related with the latest changes from pandas v2, where the to_sql method no longer expects a cursor but rather a connection.

I believe that to fix this issue the change should be done in the method _to_sql_chunk from this file

Minimal Complete Verifiable Example:

import pandas as pd
import dask.dataframe as dd

name='test'
schema_name = 'schema_name'
if_exists = 'replace'
uri = 'add here database uri'

df = pd.DataFrame([ {'i':i, 's':str(i)*2 } for i in range(4) ])
ddf = dd.from_pandas(df, npartitions=2)

ddf.to_sql(name=name, uri=uri,
                   schema=schema_name, index=False,
                   if_exists=if_exists)

Anything else we need to know?:

  • This error is happening for any type of RDBMS (SQL Server, PostGreSQL Server, MySQL)

Environment:

  • Dask version: 2024.12.1
  • Python version: 3.12
  • Operating System: MacOS Sonoma
  • Install method (conda, pip, source): pip
  • pandas version: 2.2.3
@github-actions github-actions bot added the needs triage Needs a response from a contributor label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Needs a response from a contributor
Projects
None yet
Development

No branches or pull requests

1 participant