Skip to content

Commit c6fb328

Browse files
Anirudhsekar96yehoshuadimarsky
authored andcommitted
Fixes mypy attribute issue in io/parquet by adding a hasattr check (pandas-dev#45570)
* Fixes mypy attribute issue in io/parquet by adding a hasattr check * changed attr to name attribute inside raw * combined the conditional checks on io.BufferedWriter in io/parquet * changed attribute from raw.name to name and added hasattr check * Skipped checks for graceful cleanup in windows * Changed checks for path object in parquet, linted and sorted imports * Removed sys dependency and changed pytest check for windows * Changed the condition in io/parquet to hasattr from isinstance of io.FileIO * Changed the pytest skip condition to decorator and added a message * Changed pytest skipif to mark.xfail
1 parent 9edc20b commit c6fb328

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pandas/io/parquet.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,12 @@ def write(
180180
mode="wb",
181181
is_dir=partition_cols is not None,
182182
)
183-
if isinstance(path_or_handle, io.BufferedWriter):
184-
path_or_handle = path_or_handle.raw.name
183+
if (
184+
isinstance(path_or_handle, io.BufferedWriter)
185+
and hasattr(path_or_handle, "name")
186+
and isinstance(path_or_handle.name, (str, bytes))
187+
):
188+
path_or_handle = path_or_handle.name
185189

186190
try:
187191
if partition_cols is not None:

pandas/tests/io/test_parquet.py

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from pandas._config import get_option
1515

16+
from pandas.compat import is_platform_windows
1617
from pandas.compat.pyarrow import (
1718
pa_version_under2p0,
1819
pa_version_under5p0,
@@ -728,6 +729,13 @@ def test_unsupported_float16(self, pa):
728729
df = pd.DataFrame(data=data, columns=["fp16"])
729730
self.check_external_error_on_write(df, pa, pyarrow.ArrowException)
730731

732+
@pytest.mark.xfail(
733+
is_platform_windows(),
734+
reason=(
735+
"PyArrow does not cleanup of partial files dumps when unsupported "
736+
"dtypes are passed to_parquet function in windows"
737+
),
738+
)
731739
@pytest.mark.parametrize("path_type", [str, pathlib.Path])
732740
def test_unsupported_float16_cleanup(self, pa, path_type):
733741
# #44847, #44914

0 commit comments

Comments
 (0)