Example #1
0
File: idx.py Project: garfee/blaze
    def size(self, ntype):
        # TODO: rethink this
        itemsize = ntype.size()

        if isinstance(itemsize, Integral):
            return Fixed(self.underlying.calculate(itemsize))
        else:
            return dynamic
def test_fixed_comparison():
    assert Fixed(1) != 'a'
def test_fixed_dimensions_must_be_positive():
    with pytest.raises(ValueError):
        Fixed(-1)
def test_datashape_coerces_ints():
    assert DataShape(5, 'int32')[0] == Fixed(5)
    assert DataShape(5, 'int32')[1] == int32
    ))
def test_invalid_record_literal(invalid):
    assert pytest.raises(TypeError, getitem, R, invalid)


@pytest.mark.parametrize(['names', 'typ'],
                         [(['foo', b'\xc4\x87'.decode('utf8')], unicode),
                          (['foo', 'bar'], str), (list(u'ab'), unicode)])
def test_unicode_record_names(names, typ):
    types = [int64, float64]
    record = Record(list(zip(names, types)))
    string_type, = set(map(type, record.names))
    assert record.names == names
    assert record.types == types
    assert all(isinstance(s, string_type) for s in record.names)


equiv_dshape_pairs = [(dshape('?string'), Option('string')),
                      (dshape('string'), string),
                      (dshape('datetime'), datetime_),
                      (dshape('?datetime'), Option(datetime_)),
                      (dshape('10 * int32'), 10 * int32),
                      (dshape('var * ?int32'), var * Option(int32)),
                      (dshape('10 * ?float64'), Fixed(10) * Option(float64))]


@pytest.mark.parametrize('a,b', equiv_dshape_pairs)
def test_hash_and_eq_consistency(a, b):
    assert a == b
    assert hash(a) == hash(b)