Skip to content

Commit 2ba540d

Browse files
gforsythcpcloud
authored andcommitted
refactor: dt.UUID inherits from DataType, not String
UUID no longer inherits from string. It is still possible to cast between string and UUID but they are not strict descendant/ancestor. BREAKING CHANGE: Any code that was relying implicitly on string-y behavior from UUID datatypes will need to add an explicit cast first.
1 parent 8acb1b4 commit 2ba540d

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

ibis/expr/datatypes.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ class MultiPolygon(GeoSpatial):
802802
__slots__ = ()
803803

804804

805-
class UUID(String):
805+
class UUID(DataType):
806806
"""A universally unique identifier (UUID) is a 128-bit number used to
807807
identify information in computer systems.
808808
"""
@@ -1451,6 +1451,8 @@ def can_cast_geospatial(source, target, **kwargs):
14511451

14521452

14531453
@castable.register(UUID, UUID)
1454+
@castable.register(UUID, String)
1455+
@castable.register(String, UUID)
14541456
@castable.register(MACADDR, MACADDR)
14551457
@castable.register(INET, INET)
14561458
def can_cast_special_string(source, target, **kwargs):
@@ -1569,10 +1571,3 @@ def _str_to_uuid(typ: UUID, value: str) -> _uuid.UUID:
15691571
@_normalize.register(String, _uuid.UUID)
15701572
def _uuid_to_str(typ: String, value: _uuid.UUID) -> str:
15711573
return str(value)
1572-
1573-
1574-
@_normalize.register(UUID, _uuid.UUID)
1575-
def _uuid_to_uuid(typ: UUID, value: _uuid.UUID) -> _uuid.UUID:
1576-
"""Need this to override _uuid_to_str since dt.UUID is a child of
1577-
dt.String"""
1578-
return value

ibis/tests/expr/test_datatypes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,8 @@ def test_infer_dtype(value, expected_dtype):
497497
('source', 'target'),
498498
[
499499
(dt.any, dt.string),
500+
(dt.string, dt.uuid),
501+
(dt.uuid, dt.string),
500502
(dt.null, dt.date),
501503
(dt.null, dt.any),
502504
(dt.int8, dt.int64),

0 commit comments

Comments
 (0)