Skip to content

Commit 6ffbe40

Browse files
committed
Make mypy happy again, minor refactoring using is_path instead of checking isinstance(handle, str) twice
1 parent fe9713e commit 6ffbe40

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

pandas/io/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def get_handle(
649649

650650
# Only for write methods
651651
if "r" not in mode and is_path:
652-
check_parent_directory(handle)
652+
check_parent_directory(str(handle))
653653

654654
if compression:
655655
# compression libraries do not like an explicit text-mode
@@ -714,7 +714,7 @@ def get_handle(
714714
assert not isinstance(handle, str)
715715
handles.append(handle)
716716

717-
elif isinstance(handle, str):
717+
elif is_path:
718718
# Check whether the filename is to be opened in binary mode.
719719
# Binary mode does not support 'encoding' and 'newline'.
720720
if ioargs.encoding and "b" not in ioargs.mode:

pandas/io/formats/format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ def get_buffer(buf: FilePathOrBuffer[str] | None, encoding: str | None = None):
11501150
if hasattr(buf, "write"):
11511151
yield buf
11521152
elif isinstance(buf, str):
1153-
check_parent_directory(buf)
1153+
check_parent_directory(str(buf))
11541154
with open(buf, "w", encoding=encoding, newline="") as f:
11551155
# GH#30034 open instead of codecs.open prevents a file leak
11561156
# if we have an invalid encoding argument.

0 commit comments

Comments
 (0)