Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize calls to number_of_columns() in SheetReader._iterate_columns() #25

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyexcel_io/database/querysets.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _iterate_rows(self):
return chain([self.__column_names],
self.__query_sets)

def _iterate_columns(self, row):
def _iterate_columns(self, row, ncols):
if self.__column_names is not None:
if isinstance(row, list):
for element in row:
Expand Down
2 changes: 1 addition & 1 deletion pyexcel_io/fileformat/_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def get_file_handle(self):
def _iterate_rows(self):
return csv.reader(self.get_file_handle(), **self._keywords)

def _iterate_columns(self, row):
def _iterate_columns(self, row, ncols):
for element in row:
if compact.PY2:
element = element.decode('utf-8')
Expand Down
7 changes: 4 additions & 3 deletions pyexcel_io/sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(self, sheet,
def to_array(self):
"""2 dimentional representation of the content
"""
ncols = hasattr(self, 'number_of_columns') and self.number_of_columns()
for row_index, row in enumerate(self._iterate_rows()):
row_position = self._skip_row(
row_index, self._start_row, self._row_limit)
Expand All @@ -64,7 +65,7 @@ def to_array(self):
tmp_row = []

for column_index, cell_value in enumerate(
self._iterate_columns(row)):
self._iterate_columns(row, ncols)):
column_position = self._skip_column(
column_index, self._start_column, self._column_limit)
if column_position == constants.SKIP_DATA:
Expand All @@ -89,8 +90,8 @@ def to_array(self):
def _iterate_rows(self):
return irange(self.number_of_rows())

def _iterate_columns(self, row):
for column in irange(self.number_of_columns()):
def _iterate_columns(self, row, ncols):
for column in irange(ncols):
yield self._cell_value(row, column)

def _cell_value(self, row, column):
Expand Down