Skip to content

Commit 919dc35

Browse files
authored
Merge pull request #5188 from VesnaT/excel_missings
ExcelReader: #VALUE! as np.nan
2 parents 1165816 + 0bb6f9d commit 919dc35

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

Orange/data/io.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ class ExcelReader(_BaseExcelReader):
275275
"""Reader for .xlsx files"""
276276
EXTENSIONS = ('.xlsx',)
277277
DESCRIPTION = 'Microsoft Excel spreadsheet'
278+
ERRORS = ("#VALUE!", "#DIV/0!", "#REF!", "#NUM!", "#NULL!", "#NAME?")
278279

279280
@property
280281
def workbook(self) -> openpyxl.Workbook:
@@ -296,7 +297,8 @@ def sheets(self) -> List:
296297

297298
def get_cells(self) -> Iterable:
298299
def str_(x):
299-
return str(x) if x is not None else ""
300+
return str(x) if x is not None and x not in ExcelReader.ERRORS \
301+
else ""
300302

301303
sheet = self._get_active_sheet()
302304
min_col = sheet.min_column

Orange/tests/test_xlsx_reader.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,12 @@ def test_read(self, reader: Callable[[str], io.FileFormat]):
181181
table.metas[:, 2], np.array(list("abcdefghijklmnopqrstuvw")))
182182

183183

184+
class TestMissingValues(unittest.TestCase):
185+
def test_read_errors(self):
186+
table = read_file(get_xlsx_reader, "missing")
187+
values = table.get_column_view("C")[0]
188+
self.assertTrue(np.isnan(values).all())
189+
190+
184191
if __name__ == "__main__":
185192
unittest.main()
8.79 KB
Binary file not shown.

0 commit comments

Comments
 (0)