def test_struct_literal(value): typestr = "struct<field1: string, field2: float64>" a = ibis.struct(value, type=typestr) assert a.op().value == frozendict( field1=value['field1'], field2=value['field2'] ) assert a.type() == datatypes.dtype(typestr)
def __create__(cls, *args, **kwargs): key = (cls, args, frozendict(kwargs)) try: return cls.__instances__[key] except KeyError: instance = super().__create__(*args, **kwargs) cls.__instances__[key] = instance return instance
def test_singleton_basics(): one = OneAndOnly() only = OneAndOnly() assert one is only assert len(OneAndOnly.__instances__) == 1 key = (OneAndOnly, (), frozendict()) assert OneAndOnly.__instances__[key] is one
def __init__(self, table, replacements, **kwargs): super().__init__( table=table, replacements=(replacements if not isinstance(replacements, collections.abc.Mapping) else util.frozendict(replacements)), **kwargs, )
def _struct_to_frozendict(typ: Struct, values: Mapping) -> PythonDecimal: value_types = typ.pairs values = { k: _normalize(typ[k], v) for k, v in values.items() if k in value_types } return frozendict(values)
def _map_to_frozendict(typ: Map, values: Mapping) -> PythonDecimal: values = {k: _normalize(typ.value_type, v) for k, v in values.items()} return frozendict(values)