Exemplo n.º 1
0
 def test_set(self):
     # Different reflections
     aty = types.Set(i16, reflected=True)
     bty = types.Set(i32)
     cty = types.Set(i32, reflected=True)
     self.assert_unify(aty, bty, cty)
     # Incompatible dtypes
     aty = types.Set(i16)
     bty = types.Set(types.Tuple([i16]))
     self.assert_unify_failure(aty, bty)
Exemplo n.º 2
0
def if_arr_to_series_type(typ):
    if isinstance(typ, (types.Tuple, types.UniTuple)):
        return types.Tuple([if_arr_to_series_type(t) for t in typ.types])
    if isinstance(typ, types.List):
        return types.List(if_arr_to_series_type(typ.dtype))
    if isinstance(typ, types.Set):
        return types.Set(if_arr_to_series_type(typ.dtype))
    # TODO: other types that can have Arrays inside?
    return typ
Exemplo n.º 3
0
def if_arr_to_series_type(typ):
    if isinstance(typ, types.Array) or typ in (string_array_type,
            list_string_array_type, string_array_split_view_type):
        return arr_to_series_type(typ)
    if isinstance(typ, (types.Tuple, types.UniTuple)):
        return types.Tuple([if_arr_to_series_type(t) for t in typ.types])
    if isinstance(typ, types.List):
        return types.List(if_arr_to_series_type(typ.dtype))
    if isinstance(typ, types.Set):
        return types.Set(if_arr_to_series_type(typ.dtype))
    # TODO: other types that can have Arrays inside?
    return typ
Exemplo n.º 4
0
def if_series_to_unbox(typ):
    if isinstance(typ, SeriesType):
        return UnBoxedSeriesType(typ.dtype)

    if isinstance(typ, (types.Tuple, types.UniTuple)):
        return types.Tuple([if_series_to_unbox(t) for t in typ.types])
    if isinstance(typ, types.List):
        return types.List(if_series_to_unbox(typ.dtype))
    if isinstance(typ, types.Set):
        return types.Set(if_series_to_unbox(typ.dtype))
    # TODO: other types that can have Series inside?
    return typ
Exemplo n.º 5
0
def if_series_to_array_type(typ, replace_boxed=False):
    if isinstance(typ, SeriesType):
        return series_to_array_type(typ, replace_boxed)

    if isinstance(typ, (types.Tuple, types.UniTuple)):
        return types.Tuple(
            [if_series_to_array_type(t, replace_boxed) for t in typ.types])
    if isinstance(typ, types.List):
        return types.List(if_series_to_array_type(typ.dtype, replace_boxed))
    if isinstance(typ, types.Set):
        return types.Set(if_series_to_array_type(typ.dtype, replace_boxed))
    # TODO: other types that can have Series inside?
    return typ
Exemplo n.º 6
0
def if_series_to_array_type(typ, replace_boxed=False):
    if isinstance(typ, SeriesType):
        return series_to_array_type(typ, replace_boxed)
    # XXX: Boxed series variable types shouldn't be replaced in hiframes_typed
    # it results in cast error for call dummy_unbox_series
    if replace_boxed and isinstance(typ, BoxedSeriesType):
        return series_to_array_type(typ, replace_boxed)
    if isinstance(typ, (types.Tuple, types.UniTuple)):
        return types.Tuple(
            [if_series_to_array_type(t, replace_boxed) for t in typ.types])
    if isinstance(typ, types.List):
        return types.List(if_series_to_array_type(typ.dtype, replace_boxed))
    if isinstance(typ, types.Set):
        return types.Set(if_series_to_array_type(typ.dtype, replace_boxed))
    # TODO: other types that can have Series inside?
    return typ
Exemplo n.º 7
0
 def test_disallow_set(self):
     self.assert_disallow_key(types.Set(types.intp))
     self.assert_disallow_value(types.Set(types.intp))
Exemplo n.º 8
0
def _typeof_set(val, c):
    if len(val) == 0:
        raise ValueError("Cannot type empty set")
    item = next(iter(val))
    ty = typeof_impl(item, c)
    return types.Set(ty, reflected=True)
Exemplo n.º 9
0
 def test_sets(self):
     v = set([1.0, 2.0, 3.0])
     self.assertEqual(typeof(v), types.Set(types.float64, reflected=True))
     v = frozenset(v)
     with self.assertRaises(ValueError):
         typeof(v)
Exemplo n.º 10
0
 def test_sets(self):
     v = set([1.0, 2.0, 3.0])
     self.assertEqual(typeof(v), types.Set(types.float64, reflected=True))
     v = frozenset(v)
     self.assertIs(typeof(v), None)