From a39fc7ca9fc117bf5559dfb6cff3b9cb95682cdb Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 1 Sep 2020 00:00:25 -0500 Subject: [PATCH 1/2] TYP: add type annotation #36024 --- pandas/io/excel/_xlwt.py | 12 +++++++----- setup.cfg | 3 --- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pandas/io/excel/_xlwt.py b/pandas/io/excel/_xlwt.py index 78efe77e9fe2d..8a668f32b3f6a 100644 --- a/pandas/io/excel/_xlwt.py +++ b/pandas/io/excel/_xlwt.py @@ -1,3 +1,5 @@ +from typing import Dict + import pandas._libs.json as json from pandas.io.excel._base import ExcelWriter @@ -29,12 +31,12 @@ def save(self): """ Save workbook to disk. """ - return self.book.save(self.path) + self.book.save(self.path) def write_cells( self, cells, sheet_name=None, startrow=0, startcol=0, freeze_panes=None ): - # Write the frame cells using xlwt. + from xlwt import XFStyle sheet_name = self._get_sheet_name(sheet_name) @@ -49,7 +51,7 @@ def write_cells( wks.set_horz_split_pos(freeze_panes[0]) wks.set_vert_split_pos(freeze_panes[1]) - style_dict = {} + style_dict: Dict[str, XFStyle] = {} for cell in cells: val, fmt = self._value_with_fmt(cell.val) @@ -101,14 +103,14 @@ def _style_to_xlwt( f"{key}: {cls._style_to_xlwt(value, False)}" for key, value in item.items() ] - out = f"{(line_sep).join(it)} " + out = f"{line_sep.join(it)} " return out else: it = [ f"{key} {cls._style_to_xlwt(value, False)}" for key, value in item.items() ] - out = f"{(field_sep).join(it)} " + out = f"{field_sep.join(it)} " return out else: item = f"{item}" diff --git a/setup.cfg b/setup.cfg index c10624d60aaff..2447a91f88f4e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -223,9 +223,6 @@ check_untyped_defs=False [mypy-pandas.io.excel._util] check_untyped_defs=False -[mypy-pandas.io.excel._xlwt] -check_untyped_defs=False - [mypy-pandas.io.formats.console] check_untyped_defs=False From 646ab6c52a810576151d47bffaa8fcb6afbc1136 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 1 Sep 2020 08:16:16 -0500 Subject: [PATCH 2/2] add TYPE_CHECKING --- pandas/io/excel/_xlwt.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/io/excel/_xlwt.py b/pandas/io/excel/_xlwt.py index 8a668f32b3f6a..e1f72eb533c51 100644 --- a/pandas/io/excel/_xlwt.py +++ b/pandas/io/excel/_xlwt.py @@ -1,10 +1,13 @@ -from typing import Dict +from typing import TYPE_CHECKING, Dict import pandas._libs.json as json from pandas.io.excel._base import ExcelWriter from pandas.io.excel._util import _validate_freeze_panes +if TYPE_CHECKING: + from xlwt import XFStyle + class _XlwtWriter(ExcelWriter): engine = "xlwt" @@ -36,7 +39,6 @@ def save(self): def write_cells( self, cells, sheet_name=None, startrow=0, startcol=0, freeze_panes=None ): - from xlwt import XFStyle sheet_name = self._get_sheet_name(sheet_name)