-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: custom callable in to_sql stopped working with pandas 1.4.0 #46596
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
Comments
moving to 1.4.4 |
Sorry for the slow reply, but could you provide more details regarding your testing setup with Postgres? Even with the introduction of pandas/pandas/tests/io/test_sql.py Lines 623 to 649 in d43d6e2
|
I had the same issue after I upgraded to latest Anaconda distribution ( Python 3.9, linux 64-Bit (x86) ). I did some digging around and discovered that it is the special character "@" in my password mess up the log in. Looks like the parser in the library has a bug. Maybe come from the sqlAlchemy side. The same user name password would work fine using sqlcmd: Yet it fails in python: import sqlalchemy The conn would fail here: Obviously if I do would fail too. After remove the "@ " from my password, everything worked fine. Before a fix comes out, you can get around by change your password. also, to_sql() function return -1 even though the operation is successful. the number of rows affected obviously not -1 |
The returned number of rows is the sum of the reported rows affected by whatever underlying ORM library used. https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_sql.html
|
Thanks for the report, but until we receive more context around the failure scenario this code is being tested as mentioned in #46596 (comment). Closing, but we can reopen if we get more information. |
I can confirm the same issue being experienced by me. Using with Postgres. Environment: Docker 4.12, Python v3.10-bullseye source image Affected Pandas Version: >=v1.3.6. All distributions after v1.3.5 are unable to write. I tested each version from v1.3.5 to v1.5.1, same behavior. My invocation looks like this, where the callable is referenced from official Pandas docs:
Funny behaviour that I did experience during my testing:
|
I'm having the same issue with pandas==1.5.0 and sqlalchemy== 1.4.36. And our service accounts that use pandas 1.3.4 and sqlalchemy 1.4.22 work just fine. |
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 I use custom method for PostgreSQL in
DataFrame.to_sql
according to the docummentation , the table is created with correct column names and numeric types (if it doesn't exist) but no values are imported (table is empty), no warning or error is raised in pandas nor in the database.It works in
pandas~=1.3.5
and breaks when1.4.0
or1.4.1
is installed (keeping sqlalchemy and psycopg2 on same versions). I am suspecting something related to the change thatto_sql
can now return an Int value instead or None, but couldn't find how that is related or how it can be fixed.Expected Behavior
Full
df
is imported into the table including its values.Installed Versions
INSTALLED VERSIONS
commit : 06d2301
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.13.0-39-generic
Version : #44~20.04.1-Ubuntu SMP Thu Mar 24 16:43:35 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.4.1
numpy : 1.22.3
pytz : 2022.1
dateutil : 2.8.2
pip : 20.0.2
setuptools : 45.2.0
Cython : None
pytest : 7.0.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.8.0
html5lib : None
pymysql : None
psycopg2 : 2.9.3
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : 1.3.2
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.4.3
numba : None
numexpr : 2.7.2
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : 1.0.8
s3fs : None
scipy : 1.6.3
sqlalchemy : 1.4.34
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: