-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TYP: Add types for excel writer classes #45246
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
ReadBuffer, | ||
Scalar, | ||
StorageOptions, | ||
WriteExcelBuffer, | ||
) | ||
from pandas.compat._optional import import_optional_dependency | ||
|
||
|
@@ -35,10 +36,10 @@ class OpenpyxlWriter(ExcelWriter): | |
|
||
def __init__( | ||
self, | ||
path, | ||
engine=None, | ||
date_format=None, | ||
datetime_format=None, | ||
path: FilePath | WriteExcelBuffer | ExcelWriter, | ||
engine: str | None = None, | ||
date_format: str | None = None, | ||
datetime_format: str | None = None, | ||
mode: str = "w", | ||
storage_options: StorageOptions = None, | ||
if_sheet_exists: str | None = None, | ||
|
@@ -74,7 +75,7 @@ def __init__( | |
if self.book.worksheets: | ||
self.book.remove(self.book.worksheets[0]) | ||
|
||
def save(self): | ||
def save(self) -> None: | ||
""" | ||
Save workbook to disk. | ||
""" | ||
|
@@ -217,7 +218,7 @@ def _convert_to_stop(cls, stop_seq): | |
return map(cls._convert_to_color, stop_seq) | ||
|
||
@classmethod | ||
def _convert_to_fill(cls, fill_dict): | ||
def _convert_to_fill(cls, fill_dict: dict[str, Any]): | ||
""" | ||
Convert ``fill_dict`` to an openpyxl v2 Fill object. | ||
|
||
|
@@ -418,8 +419,13 @@ def _convert_to_protection(cls, protection_dict): | |
return Protection(**protection_dict) | ||
|
||
def write_cells( | ||
self, cells, sheet_name=None, startrow=0, startcol=0, freeze_panes=None | ||
): | ||
self, | ||
cells, | ||
sheet_name: str | None = None, | ||
startrow: int = 0, | ||
startcol: int = 0, | ||
freeze_panes: tuple[int, int] | None = None, | ||
) -> None: | ||
# Write the frame cells using openpyxl. | ||
sheet_name = self._get_sheet_name(sheet_name) | ||
|
||
|
@@ -453,6 +459,8 @@ def write_cells( | |
self.sheets[sheet_name] = wks | ||
|
||
if validate_freeze_panes(freeze_panes): | ||
# for mypy | ||
assert freeze_panes is not None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if its been discussed, but i think we should move away from the assert-for-mypy pattern, since with cast/ignore mypy will alert us when it is no longer necessary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will use cast then |
||
wks.freeze_panes = wks.cell( | ||
row=freeze_panes[0] + 1, column=freeze_panes[1] + 1 | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isort complaints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had some issues with pre commit yesterday, will fix