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

fix: return UUID types as strings from .execute()/.to_pandas() #8538

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions ibis/backends/tests/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import contextlib
import uuid

import pyarrow as pa
import pytest

import ibis
import ibis.common.exceptions as com
import ibis.expr.datatypes as dt

RAW_TEST_UUID = "08f48812-7948-4718-96c7-27fa6a398db6"
TEST_UUID = uuid.UUID(RAW_TEST_UUID)
TEST_UUID = "08f48812-7948-4718-96c7-27fa6a398db6"

UUID_BACKEND_TYPE = {
"bigquery": "STRING",
Expand All @@ -31,7 +31,7 @@
def test_uuid_literal(con, backend):
backend_name = backend.name()

expr = ibis.literal(RAW_TEST_UUID, type=dt.uuid)
expr = ibis.literal(TEST_UUID, type=dt.uuid)
result = con.execute(expr)

assert result == TEST_UUID
Expand All @@ -40,6 +40,17 @@ def test_uuid_literal(con, backend):
assert con.execute(expr.typeof()) == UUID_BACKEND_TYPE[backend_name]


@pytest.mark.notimpl(["polars"], raises=NotImplementedError)
def test_uuid_to_pyarrow(con):
expr = ibis.literal(TEST_UUID, type=dt.uuid)
result = con.to_pyarrow(expr)
assert str(result) == TEST_UUID

tbl = con.tables.functional_alltypes.mutate(uuid=expr).select("uuid")
result = con.to_pyarrow(tbl.limit(2))
assert pa.types.is_string(result["uuid"].type)


@pytest.mark.notimpl(
[
"datafusion",
Expand All @@ -58,8 +69,8 @@ def test_uuid_literal(con, backend):
@pytest.mark.notimpl(["pandas", "dask"], raises=ValueError)
def test_uuid_function(con):
obj = con.execute(ibis.uuid())
assert isinstance(obj, uuid.UUID)
assert obj.version == 4
assert isinstance(obj, str)
assert uuid.UUID(obj).version == 4


@pytest.mark.notimpl(
Expand Down
6 changes: 2 additions & 4 deletions ibis/formats/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,12 @@ def convert(raw_row):

@classmethod
def convert_UUID_element(cls, _):
from uuid import UUID

def convert(value):
if value is None:
return value
elif isinstance(value, UUID):
elif isinstance(value, str):
return value
return UUID(value)
return str(value)

return convert

Expand Down
Loading