Skip to content

Commit 284b47b

Browse files
fix: change best fit formula if dataframe is empty (#157)
Co-authored-by: Adi Vaknin <DeepSpace2@users.noreply.github.com>
1 parent 4b76b82 commit 284b47b

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

styleframe/style_frame.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,12 @@ def get_range_of_cells(row_index=None, columns=None):
549549
if best_fit:
550550
if not isinstance(best_fit, (list, set, tuple)):
551551
best_fit = [best_fit]
552-
self.set_column_width_dict({column: (max(self.data_df[column].astype(str).str.len()) + self.A_FACTOR) * self.P_FACTOR
553-
for column in best_fit})
552+
self.set_column_width_dict(
553+
{
554+
column: (max(self.data_df[column].astype(str).str.len(), default=0) + self.A_FACTOR) * self.P_FACTOR
555+
for column in best_fit
556+
}
557+
)
554558

555559
for column in self._columns_width:
556560
column_letter = self._get_column_as_letter(sheet, column, startcol)

0 commit comments

Comments
 (0)