-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,72 @@ | ||
from nose.tools import assert_equal | ||
import pytest | ||
from . import PREFIX, CONN_INFO | ||
import numpy as np | ||
import datajoint as dj | ||
|
||
schema = dj.Schema(PREFIX + "_fetch_same", connection=dj.conn(**CONN_INFO)) | ||
|
||
class ProjData(dj.Manual): | ||
definition = """ | ||
id : int | ||
--- | ||
resp : float | ||
sim : float | ||
big : longblob | ||
blah : varchar(10) | ||
""" | ||
|
||
|
||
@pytest.fixture | ||
def schema_fetch_same(connection_root): | ||
schema = dj.Schema( | ||
PREFIX + "_fetch_same", | ||
context=dict(ProjData=ProjData), | ||
connection=connection_root, | ||
) | ||
schema(ProjData) | ||
ProjData().insert( | ||
[ | ||
{"id": 0, "resp": 20.33, "sim": 45.324, "big": 3, "blah": "yes"}, | ||
{ | ||
"id": 1, | ||
"resp": 94.3, | ||
"sim": 34.23, | ||
"big": {"key1": np.random.randn(20, 10)}, | ||
"blah": "si", | ||
}, | ||
{ | ||
"id": 2, | ||
"resp": 1.90, | ||
"sim": 10.23, | ||
"big": np.random.randn(4, 2), | ||
"blah": "sim", | ||
}, | ||
] | ||
) | ||
yield schema | ||
schema.drop() | ||
|
||
|
||
@pytest.fixture | ||
def projdata(): | ||
yield ProjData() | ||
|
||
|
||
class TestFetchSame: | ||
@classmethod | ||
def setup_class(cls): | ||
@schema | ||
class ProjData(dj.Manual): | ||
definition = """ | ||
id : int | ||
--- | ||
resp : float | ||
sim : float | ||
big : longblob | ||
blah : varchar(10) | ||
""" | ||
|
||
ProjData().insert( | ||
[ | ||
{"id": 0, "resp": 20.33, "sim": 45.324, "big": 3, "blah": "yes"}, | ||
{ | ||
"id": 1, | ||
"resp": 94.3, | ||
"sim": 34.23, | ||
"big": {"key1": np.random.randn(20, 10)}, | ||
"blah": "si", | ||
}, | ||
{ | ||
"id": 2, | ||
"resp": 1.90, | ||
"sim": 10.23, | ||
"big": np.random.randn(4, 2), | ||
"blah": "sim", | ||
}, | ||
] | ||
) | ||
|
||
cls.projdata = ProjData() | ||
|
||
def test_object_conversion_one(self): | ||
new = self.projdata.proj(sub="resp").fetch("sub") | ||
assert_equal(new.dtype, np.float64) | ||
|
||
def test_object_conversion_two(self): | ||
[sub, add] = self.projdata.proj(sub="resp", add="sim").fetch("sub", "add") | ||
assert_equal(sub.dtype, np.float64) | ||
assert_equal(add.dtype, np.float64) | ||
|
||
def test_object_conversion_all(self): | ||
new = self.projdata.proj(sub="resp", add="sim").fetch() | ||
assert_equal(new["sub"].dtype, np.float64) | ||
assert_equal(new["add"].dtype, np.float64) | ||
|
||
def test_object_no_convert(self): | ||
new = self.projdata.fetch() | ||
assert_equal(new["big"].dtype, "object") | ||
assert_equal(new["blah"].dtype, "object") | ||
def test_object_conversion_one(self, schema_fetch_same, projdata): | ||
new = projdata.proj(sub="resp").fetch("sub") | ||
assert new.dtype == np.float64 | ||
|
||
def test_object_conversion_two(self, schema_fetch_same, projdata): | ||
[sub, add] = projdata.proj(sub="resp", add="sim").fetch("sub", "add") | ||
assert sub.dtype == np.float64 | ||
assert add.dtype == np.float64 | ||
|
||
def test_object_conversion_all(self, schema_fetch_same, projdata): | ||
new = projdata.proj(sub="resp", add="sim").fetch() | ||
assert new["sub"].dtype == np.float64 | ||
assert new["add"].dtype == np.float64 | ||
|
||
def test_object_no_convert(self, schema_fetch_same, projdata): | ||
new = projdata.fetch() | ||
assert new["big"].dtype == "object" | ||
assert new["blah"].dtype == "object" |