From 04274b3f3904652235c1490412599398b8deb6cc Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli Date: Mon, 20 Jan 2025 09:17:12 +0000 Subject: [PATCH] test: fixup test suite for cudf.pandas (#1837) --- narwhals/_pandas_like/utils.py | 8 +++++--- tests/utils.py | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/narwhals/_pandas_like/utils.py b/narwhals/_pandas_like/utils.py index 5075a2b40d..d472fbaf2e 100644 --- a/narwhals/_pandas_like/utils.py +++ b/narwhals/_pandas_like/utils.py @@ -478,9 +478,11 @@ def native_to_narwhals_dtype( dtypes = import_dtypes_module(version) if dtype.startswith(("large_list", "list", "struct", "fixed_size_list")): - if implementation is Implementation.CUDF: - return arrow_native_to_narwhals_dtype(native_column.dtype.to_arrow(), version) - return arrow_native_to_narwhals_dtype(native_column.dtype.pyarrow_dtype, version) + native_dtype = native_column.dtype + if hasattr(native_dtype, "to_arrow"): # pragma: no cover + # cudf, cudf.pandas + return arrow_native_to_narwhals_dtype(native_dtype.to_arrow(), version) + return arrow_native_to_narwhals_dtype(native_dtype.pyarrow_dtype, version) if dtype != "object": return non_object_native_to_narwhals_dtype(dtype, version, implementation) if implementation is Implementation.DASK: diff --git a/tests/utils.py b/tests/utils.py index ca727bac07..f4f6126195 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -106,7 +106,9 @@ def assert_equal_data(result: Any, expected: dict[str, Any]) -> None: result_value = result[key] for i, (lhs, rhs) in enumerate(zip_strict(result_value, expected_value)): if isinstance(lhs, float) and not math.isnan(lhs): - are_equivalent_values = math.isclose(lhs, rhs, rel_tol=0, abs_tol=1e-6) + are_equivalent_values = rhs is not None and math.isclose( + lhs, rhs, rel_tol=0, abs_tol=1e-6 + ) elif isinstance(lhs, float) and math.isnan(lhs): are_equivalent_values = rhs is None or math.isnan(rhs) elif isinstance(rhs, float) and math.isnan(rhs):