Skip to content

Commit

Permalink
chore: restore singleton markers; fix rewrite rule; fix typo in slots
Browse files Browse the repository at this point in the history
  • Loading branch information
kszucs committed Sep 11, 2024
1 parent 0d563d6 commit 8082dc6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
4 changes: 2 additions & 2 deletions ibis/backends/pandas/rewrites.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,11 @@ def rewrite_limit(_, **kwargs):

n = n.as_table().op()
if isinstance(n, ops.Aggregate):
n = rewrite_aggregate.match(n, context={})
n = rewrite_aggregate.apply(n)

offset = offset.as_table().op()
if isinstance(offset, ops.Aggregate):
offset = rewrite_aggregate.match(offset, context={})
offset = rewrite_aggregate.apply(offset)

return PandasLimit(_.parent, n, offset)

Expand Down
8 changes: 4 additions & 4 deletions ibis/expr/datatypes/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,15 +462,15 @@ def is_variadic(self) -> bool:


@public
class Unknown(DataType):
class Unknown(DataType, singleton=True):
"""An unknown type."""

scalar = "UnknownScalar"
column = "UnknownColumn"


@public
class Primitive(DataType):
class Primitive(DataType, singleton=True):
"""Values with known size."""


Expand Down Expand Up @@ -531,7 +531,7 @@ def nbytes(self) -> int:


@public
class String(Variadic):
class String(Variadic, singleton=True):
"""A type representing a string.
Notes
Expand All @@ -546,7 +546,7 @@ class String(Variadic):


@public
class Binary(Variadic):
class Binary(Variadic, singleton=True):
"""A type representing a sequence of bytes.
Notes
Expand Down
36 changes: 23 additions & 13 deletions ibis/expr/datatypes/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,20 +432,30 @@ def test_struct_equality():
assert st3 != st2


def test_booleqn_equality():

def test_singleton_datatypes():
assert dt.null is dt.Null()
assert dt.unknown is dt.Unknown()
assert dt.boolean is dt.Boolean()
assert dt.string is dt.String()
assert dt.binary is dt.Binary()


def test_singleton_boolean():
assert dt.Boolean() == dt.boolean
assert dt.Boolean() == dt.Boolean()
assert dt.Boolean(nullable=True) == dt.boolean
assert dt.Boolean(nullable=False) != dt.boolean
assert dt.Boolean(nullable=False) == dt.Boolean(nullable=False)
assert dt.Boolean(nullable=True) == dt.Boolean(nullable=True)
assert dt.Boolean(nullable=True) != dt.Boolean(nullable=False)


def test_primite_equality():
assert dt.Int64() == dt.int64
assert dt.Int64(nullable=False) != dt.int64
assert dt.Int64(nullable=False) == dt.Int64(nullable=False)
assert dt.Boolean() is dt.boolean
assert dt.Boolean() is dt.Boolean()
assert dt.Boolean(nullable=True) is dt.boolean
assert dt.Boolean(nullable=False) is not dt.boolean
assert dt.Boolean(nullable=False) is dt.Boolean(nullable=False)
assert dt.Boolean(nullable=True) is dt.Boolean(nullable=True)
assert dt.Boolean(nullable=True) is not dt.Boolean(nullable=False)


def test_singleton_primitive():
assert dt.Int64() is dt.int64
assert dt.Int64(nullable=False) is not dt.int64
assert dt.Int64(nullable=False) is dt.Int64(nullable=False)


def test_array_type_not_equals():
Expand Down
2 changes: 1 addition & 1 deletion ibis/expr/operations/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def name(self):


@public
class Constant(Scalar):
class Constant(Scalar, singleton=True):
"""A function that produces a constant."""

shape = ds.scalar
Expand Down
2 changes: 1 addition & 1 deletion ibis/expr/operations/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class Difference(Set):
class PhysicalTable(Relation):
"""Base class for tables with a name."""

__slot__ = ("__weakref__",)
__slots__ = ("__weakref__",)

name: str
values = FrozenOrderedDict()
Expand Down

0 comments on commit 8082dc6

Please sign in to comment.