Skip to content

Commit 2b288df

Browse files
committed
BUG: Restore duck typing
Restore duck typing for fname
1 parent 8043174 commit 2b288df

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

pandas/io/stata.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1881,12 +1881,13 @@ def _open_file_binary_write(fname: FilePathOrBuffer) -> Tuple[BinaryIO, bool]:
18811881
own : bool
18821882
True if the file was created, otherwise False
18831883
"""
1884-
if isinstance(fname, IOBase):
1885-
return fname, False
1884+
if hasattr(fname, "write"):
1885+
# See https://github.com/python/mypy/issues/1424 for hasattr challenges
1886+
return fname, False # type: ignore
18861887
elif isinstance(fname, (str, Path)):
18871888
return open(fname, "wb"), True
18881889
else:
1889-
raise ValueError("fname must be a binary file, buffer or path-like.")
1890+
raise TypeError("fname must be a binary file, buffer or path-like.")
18901891

18911892

18921893
def _set_endianness(endianness: str) -> str:

0 commit comments

Comments
 (0)