Skip to content

Commit

Permalink
refactor(api): remove string as a parent type from expression API
Browse files Browse the repository at this point in the history
BREAKING CHANGE: UUID, MACADDR and INET are no longer subclasses of strings. Cast those values to `string` to enable use of the string APIs.
  • Loading branch information
cpcloud authored and jcrist committed Sep 8, 2023
1 parent 6ad1e96 commit 2db98fb
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ibis/backends/base/sql/registry/literal.py
Expand Up @@ -96,7 +96,7 @@ def literal(translator, op):

if dtype.is_boolean():
typeclass = "boolean"
elif dtype.is_string():
elif dtype.is_string() or dtype.is_inet() or dtype.is_macaddr():
typeclass = "string"
elif dtype.is_date():
typeclass = "date"
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/clickhouse/compiler/values.py
Expand Up @@ -451,7 +451,7 @@ def _literal(op, **kw):
elif dtype.is_inet():
v = str(value)
return f"toIPv6({v!r})" if ":" in v else f"toIPv4({v!r})"
elif dtype.is_string():
elif dtype.is_string() or dtype.is_macaddr():
quoted = value.replace("'", "''").replace("\\", "\\\\")
return f"'{quoted}'"
elif dtype.is_decimal():
Expand Down
4 changes: 2 additions & 2 deletions ibis/expr/datatypes/core.py
Expand Up @@ -1017,15 +1017,15 @@ class UUID(DataType):


@public
class MACADDR(String):
class MACADDR(DataType):
"""Media Access Control (MAC) address of a network interface."""

scalar = "MACADDRScalar"
column = "MACADDRColumn"


@public
class INET(String):
class INET(DataType):
"""IP addresses."""

scalar = "INETScalar"
Expand Down
2 changes: 1 addition & 1 deletion ibis/expr/datatypes/value.py
Expand Up @@ -287,7 +287,7 @@ def normalize(typ, value):
return json.dumps(value)
elif dtype.is_binary():
return bytes(value)
elif dtype.is_string():
elif dtype.is_string() or dtype.is_macaddr() or dtype.is_inet():
return str(value)
elif dtype.is_decimal():
return normalize_decimal(value, precision=dtype.precision, scale=dtype.scale)
Expand Down
14 changes: 7 additions & 7 deletions ibis/expr/types/inet.py
Expand Up @@ -2,34 +2,34 @@

from public import public

from ibis.expr.types.strings import StringColumn, StringScalar, StringValue
from ibis.expr.types.generic import Column, Scalar, Value


@public
class MACADDRValue(StringValue):
class MACADDRValue(Value):
pass


@public
class MACADDRScalar(StringScalar, MACADDRValue):
class MACADDRScalar(Scalar, MACADDRValue):
pass


@public
class MACADDRColumn(StringColumn, MACADDRValue):
class MACADDRColumn(Column, MACADDRValue):
pass


@public
class INETValue(StringValue):
class INETValue(Value):
pass


@public
class INETScalar(StringScalar, INETValue):
class INETScalar(Scalar, INETValue):
pass


@public
class INETColumn(StringColumn, INETValue):
class INETColumn(Column, INETValue):
pass
8 changes: 4 additions & 4 deletions ibis/expr/types/uuid.py
Expand Up @@ -2,19 +2,19 @@

from public import public

from ibis.expr.types.strings import StringColumn, StringScalar, StringValue
from ibis.expr.types.generic import Column, Scalar, Value


@public
class UUIDValue(StringValue):
class UUIDValue(Value):
pass


@public
class UUIDScalar(StringScalar, UUIDValue):
class UUIDScalar(Scalar, UUIDValue):
pass


@public
class UUIDColumn(StringColumn, UUIDValue):
class UUIDColumn(Column, UUIDValue):
pass
2 changes: 2 additions & 0 deletions ibis/formats/numpy.py
Expand Up @@ -80,6 +80,8 @@ def from_ibis(cls, dtype: dt.DataType) -> np.dtype:
or dtype.is_unknown()
or dtype.is_uuid()
or dtype.is_geospatial()
or dtype.is_inet()
or dtype.is_macaddr()
):
return np.dtype("object")
else:
Expand Down

0 comments on commit 2db98fb

Please sign in to comment.