diff --git a/ibis/backends/pandas/rewrites.py b/ibis/backends/pandas/rewrites.py index 87ab218c472b1..d5e1af1e88760 100644 --- a/ibis/backends/pandas/rewrites.py +++ b/ibis/backends/pandas/rewrites.py @@ -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) diff --git a/ibis/expr/datatypes/core.py b/ibis/expr/datatypes/core.py index 3efde71630cdc..569e3ad4c0e85 100644 --- a/ibis/expr/datatypes/core.py +++ b/ibis/expr/datatypes/core.py @@ -462,7 +462,7 @@ def is_variadic(self) -> bool: @public -class Unknown(DataType): +class Unknown(DataType, singleton=True): """An unknown type.""" scalar = "UnknownScalar" @@ -470,7 +470,7 @@ class Unknown(DataType): @public -class Primitive(DataType): +class Primitive(DataType, singleton=True): """Values with known size.""" @@ -531,7 +531,7 @@ def nbytes(self) -> int: @public -class String(Variadic): +class String(Variadic, singleton=True): """A type representing a string. Notes @@ -546,7 +546,7 @@ class String(Variadic): @public -class Binary(Variadic): +class Binary(Variadic, singleton=True): """A type representing a sequence of bytes. Notes diff --git a/ibis/expr/datatypes/tests/test_core.py b/ibis/expr/datatypes/tests/test_core.py index cc48dcbca40f5..c1364509476ad 100644 --- a/ibis/expr/datatypes/tests/test_core.py +++ b/ibis/expr/datatypes/tests/test_core.py @@ -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(): diff --git a/ibis/expr/operations/generic.py b/ibis/expr/operations/generic.py index a509964a0de30..d461f129fa30c 100644 --- a/ibis/expr/operations/generic.py +++ b/ibis/expr/operations/generic.py @@ -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 diff --git a/ibis/expr/operations/relations.py b/ibis/expr/operations/relations.py index 74983a5d0d96f..44e7a20bdc10c 100644 --- a/ibis/expr/operations/relations.py +++ b/ibis/expr/operations/relations.py @@ -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()