Skip to content

BUG: Pandas converts int to float while reading from database if column has Null in it #43878

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

Closed
3 tasks done
AltafHussain4748 opened this issue Oct 4, 2021 · 1 comment
Closed
3 tasks done
Labels
Closing Candidate May be closeable, needs more eyeballs IO SQL to_sql, read_sql, read_sql_query Usage Question

Comments

@AltafHussain4748
Copy link

  • 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 master branch of pandas.

Reproducible Example

import pandas as pd

ps.read_sql("query", con)

Issue Description

I am trying to read a stored procedure by using pandas.read_sql method in Python by using the pyodbc driver. The issue I have is when Pandas reads data, it converts int columns to float which have Null values in it.

Expected Behavior

import pandas as pd

ps.read_sql("query", con)

Installed Versions

INSTALLED VERSIONS

commit : 73c6825
python : 3.8.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.11.0-37-generic
Version : #41~20.04.2-Ubuntu SMP Fri Sep 24 09:06:38 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.3.3
numpy : 1.21.2
pytz : 2021.1
dateutil : 2.8.2
pip : 20.0.2
setuptools : 44.0.0
Cython : None
pytest : 6.2.5
hypothesis : None
sphinx : 4.2.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.27.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.4.23
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

import pandas as pd

@AltafHussain4748 AltafHussain4748 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 4, 2021
@phofl
Copy link
Member

phofl commented Oct 4, 2021

NaN is a float, hence converted to float when missing values are in a column. If this does not cover your issue please provide something reproducible

@phofl phofl added Closing Candidate May be closeable, needs more eyeballs IO SQL to_sql, read_sql, read_sql_query Usage Question and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closing Candidate May be closeable, needs more eyeballs IO SQL to_sql, read_sql, read_sql_query Usage Question
Projects
None yet
Development

No branches or pull requests

3 participants