Skip to content

Commit bb2e5fe

Browse files
Merge branch 'dev' of https://github.com/datajoint/datajoint-python into custom-attribute-type
2 parents 20cf0a6 + fc21b5c commit bb2e5fe

File tree

5 files changed

+34
-18
lines changed

5 files changed

+34
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Support for pandas and order by "KEY" (#459, #537, #538, #541) PR #534
2020
* Support file attachment datatype and configurable blob storage (#467, #475, #480, #497) PR #532
2121
* Increase default display rows (#523) PR #526
22-
* Bugfixes (#521, #205, #279, #570, #581, #597, #596, #618, #633)
22+
* Bugfixes (#521, #205, #279, #477, #570, #581, #597, #596, #618, #633, #643, #644, #647)
2323

2424
### 0.11.3 -- Jul 26, 2019
2525
* Fix incompatibility with pyparsing 2.4.1 (#629) PR #631

datajoint/fetch.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,14 @@ def __call__(self, *attrs, offset=None, limit=None, order_by=None, format=None,
177177
else:
178178
ret = list(cur.fetchall())
179179
record_type = (heading.as_dtype if not ret else np.dtype(
180-
[(name, type(value))
181-
if heading.as_dtype[name] == 'O' and isinstance(
182-
value, numbers.Number) # value of blob is packed here
180+
[(name, type(value)) # use the first element to determine the type for blobs
181+
if heading[name].is_blob and isinstance(value, numbers.Number)
183182
else (name, heading.as_dtype[name])
184-
for value, name
185-
in zip(ret[0], heading.as_dtype.names)]))
186-
ret = np.array(ret, dtype=record_type)
183+
for value, name in zip(ret[0], heading.as_dtype.names)]))
184+
try:
185+
ret = np.array(ret, dtype=record_type)
186+
except Exception as e:
187+
raise
187188
for name in heading:
188189
ret[name] = list(map(partial(get, heading[name]), ret[name]))
189190
if format == "frame":

tests/schema.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ class TTest3(dj.Manual):
3939
"""
4040

4141

42+
@schema
43+
class NullableNumbers(dj.Manual):
44+
definition = """
45+
key : int
46+
---
47+
fvalue = null : float
48+
dvalue = null : double
49+
ivalue = null : int
50+
"""
51+
52+
4253
@schema
4354
class TTestExtra(dj.Manual):
4455
"""

tests/test_fetch.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,15 @@ def test_decimal(self):
203203
assert_true(len(rel & keys[0]) == 1)
204204
keys = rel.fetch(dj.key)
205205
assert_true(len(rel & keys[1]) == 1)
206+
207+
def test_nullable_numbers(self):
208+
""" test mixture of values and nulls in numeric attributes """
209+
table = schema.NullableNumbers()
210+
table.insert((
211+
(k, np.random.randn(), np.random.randint(-1000, 1000), np.random.randn())
212+
for k in range(10)))
213+
table.insert1((100, None, None, None))
214+
f, d, i = table.fetch('fvalue', 'dvalue', 'ivalue')
215+
assert_true(None in i)
216+
assert_true(any(np.isnan(d)))
217+
assert_true(any(np.isnan(f)))

tests/test_fetch_same.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,23 @@ class TestFetchSame:
3535

3636
@staticmethod
3737
def test_object_conversion_one():
38-
39-
new = ProjData.proj(sub='resp-sim').fetch('sub')
40-
38+
new = ProjData.proj(sub='resp').fetch('sub')
4139
assert_equal(new.dtype, np.float64)
4240

4341
@staticmethod
4442
def test_object_conversion_two():
45-
46-
[sub, add] = ProjData.proj(sub='resp-sim', add='resp+sim').fetch(
47-
'sub', 'add')
48-
43+
[sub, add] = ProjData.proj(sub='resp', add='sim').fetch('sub', 'add')
4944
assert_equal(sub.dtype, np.float64)
5045
assert_equal(add.dtype, np.float64)
5146

5247
@staticmethod
5348
def test_object_conversion_all():
54-
55-
new = ProjData.proj(sub='resp-sim', add='resp+sim').fetch()
56-
49+
new = ProjData.proj(sub='resp', add='sim').fetch()
5750
assert_equal(new['sub'].dtype, np.float64)
5851
assert_equal(new['add'].dtype, np.float64)
5952

6053
@staticmethod
6154
def test_object_no_convert():
62-
6355
new = ProjData.fetch()
6456
assert_equal(new['big'].dtype, 'object')
6557
assert_equal(new['blah'].dtype, 'object')

0 commit comments

Comments
 (0)