Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
burnpanck committed Aug 15, 2023
1 parent d3c7200 commit 87fd933
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions pandas/io/excel/_xlrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,17 @@ def _parse_cell(cell_contents, cell_typ):
elif cell_typ == XL_CELL_NUMBER:
# GH5394 - Excel 'numbers' are always floats
# it's a minimal perf hit and less surprising
val = int(cell_contents)
if val == cell_contents:
cell_contents = val
try:
val = int(cell_contents)
except Exception:
# GH54564 - if the cell contents are NaN/Inf, we get an exception;
# that is just another case where we don't want to convert.
# The exception filter is quite general on purpose: whenever
# the cell content cannot be converted to int - just don't.
pass
else:
if val == cell_contents:
cell_contents = val
return cell_contents

data = []
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/excel/test_xlrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def test_nan_in_xls(datapath):
# GH 54564
path = datapath("io", "data", "excel", "test6.xls")

expected = pd.DataFrame(np.r_[:3, np.nan].reshape(2, 2))
expected = pd.DataFrame(np.r_[:3, np.nan].reshape(2, 2)).astype(float)

result = pd.read_excel(path)
result = pd.read_excel(path, header=None).astype(float)

tm.assert_frame_equal(result, expected)

Expand Down

0 comments on commit 87fd933

Please sign in to comment.