Skip to content

Commit 87fd933

Browse files
committed
1 parent d3c7200 commit 87fd933

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

pandas/io/excel/_xlrd.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,17 @@ def _parse_cell(cell_contents, cell_typ):
120120
elif cell_typ == XL_CELL_NUMBER:
121121
# GH5394 - Excel 'numbers' are always floats
122122
# it's a minimal perf hit and less surprising
123-
val = int(cell_contents)
124-
if val == cell_contents:
125-
cell_contents = val
123+
try:
124+
val = int(cell_contents)
125+
except Exception:
126+
# GH54564 - if the cell contents are NaN/Inf, we get an exception;
127+
# that is just another case where we don't want to convert.
128+
# The exception filter is quite general on purpose: whenever
129+
# the cell content cannot be converted to int - just don't.
130+
pass
131+
else:
132+
if val == cell_contents:
133+
cell_contents = val
126134
return cell_contents
127135

128136
data = []

pandas/tests/io/excel/test_xlrd.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ def test_nan_in_xls(datapath):
4949
# GH 54564
5050
path = datapath("io", "data", "excel", "test6.xls")
5151

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

54-
result = pd.read_excel(path)
54+
result = pd.read_excel(path, header=None).astype(float)
5555

5656
tm.assert_frame_equal(result, expected)
5757

0 commit comments

Comments
 (0)