<commit_before>from __future__ import absolute_import, division, print_function

import pytest
from datashape import discover, dshape
bcolz = pytest.importorskip('bcolz')

import numpy as np

from blaze.bcolz import into, chunks
from blaze.expr import Symbol
from blaze.compute.core import compute


b = bcolz.ctable([[1, 2, 3], [1., 2., 3.]],
                 names=['a', 'b'])

t = Symbol('t', 'var * {a: int32, b: float64}')


to = Symbol('to', 'var * {a: int32, b: float64}')
bo = bcolz.ctable(np.array([(1, 1.), (2, 2.), (3, np.nan)],
                           dtype=[('a', 'i8'), ('b', 'f8')]))


def test_discover():
    assert discover(b) == dshape('3 * {a: int64, b: float64}')
    assert discover(b['a']) == dshape('3 * int64')


def test_chunks():
    assert len(list(chunks(b, chunksize=2))) == 2
    assert (next(chunks(b, chunksize=2)) == into(np.array(0), b)[:2]).all()


def test_reductions():
    assert compute(t.a.sum(), b) == 6
    assert compute(t.a.min(), b) == 1
    assert compute(t.a.max(), b) == 3
    assert compute(t.a.mean(), b) == 2.0
    assert abs(compute(t.a.std(), b) - np.std([1, 2, 3])) < 1e-5
    assert abs(compute(t.a.var(), b) - np.var([1, 2, 3])) < 1e-5
    assert abs(compute(t.a.std(unbiased=True), b) - np.std([1, 2, 3],
                                                           ddof=1)) < 1e-5
    assert abs(compute(t.a.var(unbiased=True), b) - np.var([1, 2, 3],
                                                           ddof=1)) < 1e-5
    assert len(list(compute(t.distinct(), b))) == 3<commit_msg>other bcolz test specifies dtype<commit_after>from __future__ import absolute_import, division, print_function

import pytest
from datashape import discover, dshape
bcolz = pytest.importorskip('bcolz')

import numpy as np

from blaze.bcolz import into, chunks
from blaze.expr import Symbol
from blaze.compute.core import compute


b = bcolz.ctable(np.array([(1, 1.), (2, 2.), (3, 3.)],
                          dtype=[('a', 'i8'), ('b', 'f8')]))

t = Symbol('t', 'var * {a: int64, b: float64}')


to = Symbol('to', 'var * {a: int64, b: float64}')
bo = bcolz.ctable(np.array([(1, 1.), (2, 2.), (3, np.nan)],
                           dtype=[('a', 'i8'), ('b', 'f8')]))


def test_discover():
    assert discover(b) == dshape('3 * {a: int64, b: float64}')
    assert discover(b['a']) == dshape('3 * int64')


def test_chunks():
    assert len(list(chunks(b, chunksize=2))) == 2
    assert (next(chunks(b, chunksize=2)) == into(np.array(0), b)[:2]).all()


def test_reductions():
    assert compute(t.a.sum(), b) == 6
    assert compute(t.a.min(), b) == 1
    assert compute(t.a.max(), b) == 3
    assert compute(t.a.mean(), b) == 2.0
    assert abs(compute(t.a.std(), b) - np.std([1, 2, 3])) < 1e-5
    assert abs(compute(t.a.var(), b) - np.var([1, 2, 3])) < 1e-5
    assert abs(compute(t.a.std(unbiased=True), b) - np.std([1, 2, 3],
                                                           ddof=1)) < 1e-5
    assert abs(compute(t.a.var(unbiased=True), b) - np.var([1, 2, 3],
                                                           ddof=1)) < 1e-5
    assert len(list(compute(t.distinct(), b))) == 3
{'fraction_non_alphanumeric': 0.20323398858592265, 'fraction_numerical': 0.039949270767279645, 'mean_word_length': 2.5094549499443826, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4926653', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1164, 'n_words': 289}