Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1547 from kwmsmith/feature/py35
Python 3.5 support
- Loading branch information
Showing
14 changed files
with
144 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,52 @@ | ||
import pytest | ||
tables = pytest.importorskip('tables') | ||
|
||
from blaze.compute.hdfstore import * | ||
from blaze.utils import tmpfile | ||
from datashape import discover, dshape | ||
from blaze import symbol, compute, data | ||
from blaze import symbol, discover, compute, pre_compute | ||
import pandas as pd | ||
from datetime import datetime | ||
from odo import Chunks, into | ||
import os | ||
from odo import Chunks, odo | ||
|
||
|
||
try: | ||
f = pd.HDFStore('foo') | ||
except (RuntimeError, ImportError) as e: | ||
pytest.skip('skipping test_hdfstore.py %s' % e) | ||
else: | ||
f.close() | ||
os.remove('foo') | ||
@pytest.fixture | ||
def df(): | ||
return pd.DataFrame([['a', 1, 10., datetime(2000, 1, 1)], | ||
['ab', 2, 20., datetime(2000, 2, 2)], | ||
['abc', 3, 30., datetime(2000, 3, 3)], | ||
['abcd', 4, 40., datetime(2000, 4, 4)]], | ||
columns=['name', 'a', 'b', 'time']) | ||
|
||
|
||
df = pd.DataFrame([['a', 1, 10., datetime(2000, 1, 1)], | ||
['ab', 2, 20., datetime(2000, 2, 2)], | ||
['abc', 3, 30., datetime(2000, 3, 3)], | ||
['abcd', 4, 40., datetime(2000, 4, 4)]], | ||
columns=['name', 'a', 'b', 'time']) | ||
@pytest.fixture | ||
def s(hdf): | ||
return symbol('s', discover(hdf)) | ||
|
||
|
||
def test_hdfstore(): | ||
@pytest.yield_fixture(params=['fixed', 'table']) | ||
def hdf(df, request): | ||
with tmpfile('.hdf5') as fn: | ||
df.to_hdf(fn, '/appendable', format='table') | ||
df.to_hdf(fn, '/fixed') | ||
df.to_hdf(fn, '/data', format=request.param) | ||
df.to_hdf(fn, '/nested/data', format=request.param) | ||
with pd.HDFStore(fn, mode='r') as r: | ||
yield r | ||
|
||
hdf = data('hdfstore://%s' % fn) | ||
s = symbol('s', discover(hdf)) | ||
|
||
assert isinstance(compute(s.fixed, hdf), | ||
(pd.DataFrame, pd.io.pytables.Fixed)) | ||
assert isinstance(compute(s.appendable, hdf), | ||
(pd.io.pytables.AppendableFrameTable, Chunks)) | ||
def test_basic_compute(hdf, s): | ||
result = compute(s.data, hdf) | ||
types = ( | ||
pd.DataFrame, | ||
pd.io.pytables.Fixed, | ||
pd.io.pytables.AppendableFrameTable, | ||
Chunks | ||
) | ||
assert isinstance(result, types) | ||
|
||
s = symbol('s', discover(df)) | ||
f = data('hdfstore://%s::/fixed' % fn) | ||
a = data('hdfstore://%s::/appendable' % fn) | ||
assert isinstance(pre_compute(s, a), Chunks) | ||
|
||
hdf.data.close() | ||
f.data.parent.close() | ||
a.data.parent.close() | ||
def test_pre_compute(hdf, s): | ||
result = pre_compute(s, hdf.get_storer('data')) | ||
assert isinstance(result, (pd.DataFrame, Chunks)) | ||
|
||
|
||
|
||
def test_groups(): | ||
with tmpfile('.hdf5') as fn: | ||
df.to_hdf(fn, '/data/fixed') | ||
|
||
hdf = data('hdfstore://%s' % fn) | ||
assert dshape(discover(hdf)) == dshape(discover({'data': {'fixed': df}})) | ||
|
||
s = symbol('s', discover(hdf)) | ||
|
||
assert list(compute(s.data.fixed, hdf).a) == [1, 2, 3, 4] | ||
|
||
hdf.data.close() | ||
def test_groups(hdf, df, s): | ||
assert discover(hdf) == discover(dict(data=df, nested=dict(data=df))) | ||
assert odo(compute(s.nested.data.a, hdf), list) == [1, 2, 3, 4] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.