Skip to content

Commit 1364f30

Browse files
authored
chore: make both mypy and pyright happy (#370)
1 parent f0fdf3f commit 1364f30

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

python/fastexcel/__init__.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
from pathlib import Path
1919

2020
try:
21-
import pyarrow as pa
21+
import importlib.util
2222

23+
importlib.util.find_spec("pyarrow")
2324
_PYARROW_AVAILABLE = True
2425
except ImportError:
25-
pa = None
2626
_PYARROW_AVAILABLE = False
2727

2828
from ._fastexcel import (
@@ -458,21 +458,34 @@ def load_table(
458458
:param dtypes: An optional dtype (for all columns)
459459
or dict of dtypes with keys as column indices or names.
460460
"""
461-
output = self._reader.load_table( # type:ignore[call-overload,misc]
462-
name=name,
463-
header_row=header_row,
464-
column_names=column_names,
465-
skip_rows=skip_rows,
466-
n_rows=n_rows,
467-
schema_sample_rows=schema_sample_rows,
468-
dtype_coercion=dtype_coercion,
469-
use_columns=use_columns,
470-
dtypes=dtypes,
471-
eager=eager,
472-
)
473461
if eager:
474-
return output
475-
return ExcelTable(output)
462+
return self._reader.load_table(
463+
name=name,
464+
header_row=header_row,
465+
column_names=column_names,
466+
skip_rows=skip_rows,
467+
n_rows=n_rows,
468+
schema_sample_rows=schema_sample_rows,
469+
dtype_coercion=dtype_coercion,
470+
use_columns=use_columns,
471+
dtypes=dtypes,
472+
eager=True,
473+
)
474+
else:
475+
return ExcelTable(
476+
self._reader.load_table(
477+
name=name,
478+
header_row=header_row,
479+
column_names=column_names,
480+
skip_rows=skip_rows,
481+
n_rows=n_rows,
482+
schema_sample_rows=schema_sample_rows,
483+
dtype_coercion=dtype_coercion,
484+
use_columns=use_columns,
485+
dtypes=dtypes,
486+
eager=False,
487+
)
488+
)
476489

477490
def load_sheet_eager(
478491
self,

python/tests/benchmarks/memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import argparse
22
from enum import Enum
33

4-
from readers import fastexcel_read, pyxl_read, xlrd_read
4+
from .readers import fastexcel_read, pyxl_read, xlrd_read
55

66

77
class Engine(str, Enum):

python/tests/benchmarks/readers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ def pyxl_read(test_file_path: str):
99
rows = ws.iter_rows()
1010
rows = ws.values
1111
for row in rows:
12-
for value in row:
13-
value
12+
for _ in row:
13+
pass
1414

1515

1616
def xlrd_read(test_file_path: str):
1717
wb = open_workbook(test_file_path)
1818
for ws in wb.sheets():
1919
for idx in range(ws.nrows):
20-
for value in ws.row_values(idx):
21-
value
20+
for _ in ws.row_values(idx):
21+
pass
2222

2323

2424
def fastexcel_read(test_file_path: str):

python/tests/benchmarks/speed.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"""
44

55
import pytest
6-
from readers import fastexcel_read, pyxl_read, xlrd_read
6+
7+
from .readers import fastexcel_read, pyxl_read, xlrd_read
78

89

910
@pytest.fixture

0 commit comments

Comments
 (0)