Skip to content

BUG: read_excel does not convert integral floats to ints when backed by openpyxl #46988

Closed
@mttr

Description

@mttr

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
print(pd.read_excel("./Numbers.xlsx"))

sample file: Numbers.xlsx

Issue Description

Per the documentation (see: convert_float), by default read_excel should convert any integral float into an integer. Here is the output from the above code using a simple xslx file with a single column of integers:

    1.0
0   2.0
1   3.0
2   4.0
3   5.0
4   6.0
5   7.0
6   8.0
7   9.0
8  10.0
9  11.0

As you can see, the values from that column are represented by floats instead of ints.

This appears to be a regression (this worked as expected in 1.2.4) introduced by this PR, though it's worth noting that this was made under the belief that openpyxl did this conversion already (perhaps it did at the time- I haven't looked into it yet).

Other excel engines look to be unaffected.

Expected Behavior

    1
0   2
1   3
2   4
3   5
4   6
5   7
6   8
7   9
8  10
9  11

Installed Versions

INSTALLED VERSIONS
------------------
commit           : 4bfe3d07b4858144c219b9346329027024102ab6
python           : 3.9.1.final.0
python-bits      : 64
OS               : Darwin
OS-release       : 21.4.0
Version          : Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64
machine          : x86_64
processor        : i386
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 1.4.2
numpy            : 1.22.3
pytz             : 2021.1
dateutil         : 2.8.1
pip              : 22.0.4
setuptools       : 49.2.1
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 3.0.1
IPython          : 7.24.1
pandas_datareader: None
bs4              : None
bottleneck       : None
brotli           : None
fastparquet      : None
fsspec           : None
gcsfs            : None
markupsafe       : 2.0.1
matplotlib       : None
numba            : None
numexpr          : None
odfpy            : None
openpyxl         : 3.0.9
pandas_gbq       : None
pyarrow          : None
pyreadstat       : None
pyxlsb           : 1.0.9
s3fs             : None
scipy            : None
snappy           : None
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : 2.0.1
xlwt             : None
zstandard        : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO Excelread_excel, to_excelRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions