Skip to content
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

Fixes mypy attribute issue in io/parquet by adding a hasattr check #45570

Merged
merged 10 commits into from
Jan 23, 2022
Merged
8 changes: 6 additions & 2 deletions pandas/io/parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,12 @@ def write(
mode="wb",
is_dir=partition_cols is not None,
)
if isinstance(path_or_handle, io.BufferedWriter):
path_or_handle = path_or_handle.raw.name
if (
isinstance(path_or_handle, io.BufferedWriter)
and hasattr(path_or_handle, "name")
and isinstance(path_or_handle.name, (str, bytes))
):
path_or_handle = path_or_handle.name

try:
if partition_cols is not None:
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from pandas._config import get_option

from pandas.compat import is_platform_windows
from pandas.compat.pyarrow import (
pa_version_under2p0,
pa_version_under5p0,
Expand Down Expand Up @@ -736,6 +737,10 @@ def test_unsupported_float16_cleanup(self, pa, path_type):
data = np.arange(2, 10, dtype=np.float16)
df = pd.DataFrame(data=data, columns=["fp16"])

# Cleanup fails in windows
if is_platform_windows():
Anirudhsekar96 marked this conversation as resolved.
Show resolved Hide resolved
pytest.skip()

with tm.ensure_clean() as path_str:
path = path_type(path_str)
with tm.external_error_raised(pyarrow.ArrowException):
Expand Down