Skip to content

Commit

Permalink
Merge pull request #47 from jm-begon/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jm-begon authored Mar 22, 2019
2 parents 6fb70ce + 2e6ebfc commit fe29620
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
4 changes: 2 additions & 2 deletions clustertools/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,9 @@ def numpyfy(self, squeeze=True):
if len(self.parameters) == 0:
# Only metrics, everything is in metadata
return np.array([self.data[self.hash(m, self.metadata)]
for m in self.metrics])
for m in self.metrics], dtype=np.float)

arr = np.array([arr.numpyfy() for arr in self])
arr = np.array([arr.numpyfy() for arr in self], dtype=np.float)
if squeeze and arr.shape[-1] == 1:
arr = arr.squeeze()
return arr
Expand Down
46 changes: 37 additions & 9 deletions clustertools/test/test_datacube.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-

from unittest import SkipTest

from nose.tools import assert_dict_equal, assert_not_in, assert_equal, \
assert_not_equal, assert_in, assert_true, assert_raises
Expand Down Expand Up @@ -306,8 +306,6 @@ def test_call_indexing():
assert_raises(KeyError, cube, "f3")




def test_indexing_name():
name, metadata, params, dom, metrics, d = alldiff()
cube = build_cube(name, d)
Expand Down Expand Up @@ -340,8 +338,6 @@ def test_call_indexing_name():
assert_equal(cube(metric="f2", w=0, x="2"), 52)




def test_slicing():
name, metadata, params, dom, metrics, d = alldiff()
cube = build_cube(name, d)
Expand Down Expand Up @@ -424,8 +420,10 @@ def test_indexing_path():


def test_numpyfy():
import numpy as np
# TODO skip if not numpy
try:
import numpy as np
except ImportError:
raise SkipTest("numpy is not installed")
name, metadata, params, dom, metrics, d = alldiff()
cube = build_cube(name, d)
cube2 = cube[0, 0]
Expand Down Expand Up @@ -473,8 +471,8 @@ def test_items():
def test_ood():
name, metadata, params, dom, metrics, d = some_ood()
cube = build_cube(name, d)
expected_ood = [( {"x":"2", "w":"5"}, "f1"),
( {"x":"2", "w":"5"}, "f2")]
expected_ood = [({"x": "2", "w": "5"}, "f1"),
({"x": "2", "w": "5"}, "f2")]
ood = cube.out_of_domain()
assert_equal(len(ood), len(expected_ood))
assert_dict_equal(expected_ood[0][0], ood[0][0])
Expand All @@ -485,6 +483,36 @@ def test_ood():
m.sort()
assert_equal(m, exp_m)


def test_ood_nan():
# missing values should be marked as nan
try:
import numpy as np
except ImportError:
raise SkipTest("numpy is not installed")
name, metadata, params, dom, metrics, d = some_ood()
cube = build_cube(name, d)
arr = cube.numpyfy(True)
assert_true(np.issubdtype(arr.dtype, np.float))
try:
assert_true(np.isnan(arr).any())
except:
assert_true(False, "Exception was raised, nan is not working")


def test_ood_iter_dimensions():
name, metadata, params, dom, metrics, d = some_ood()
cube = build_cube(name, d)
for (x, w), cube_i in cube.iter_dimensions("x", "w"):
x = int(x)
w = int(w)
v = cube_i("f1")
if x == 2 and w == 5:
assert_true(v is None)
else:
assert_true(v is not None)


# def test_max_hypercube():
# name, metadata, params, dom, metrics, d = some_ood()
# cube = build_cube(name, d)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
with open('README.md') as f:
LONG_DESCRIPTION = f.read()
CLASSIFIERS = [
'Development Status :: 2 - Pre-Alp ha',
'Development Status :: 2 - Pre-Alpha',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
Expand Down

0 comments on commit fe29620

Please sign in to comment.