Skip to content

Commit 84edcc4

Browse files
committed
Fix np array initialization #4
Also don't branch on list types in get_value.
1 parent 8c717b7 commit 84edcc4

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

objectbox/model/entity.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,9 @@ def fill_properties(self):
8585
def get_value(self, object, prop: Property):
8686
# in case value is not overwritten on the object, it's the Property object itself (= as defined in the Class)
8787
val = getattr(object, prop._name)
88-
if prop._py_type == list:
88+
if prop._py_type == np.ndarray:
8989
if (val == np.array(prop)).all():
90-
return prop._py_type()
91-
elif prop._py_type == np.ndarray:
92-
if (val == np.array(prop)).all():
93-
return np.array([0])
90+
return np.array([])
9491
elif val == prop:
9592
return prop._py_type() # default (empty) value for the given type
9693
return val

tests/common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ def assert_equal(actual: TestEntity, expected: TestEntity):
5555
assert_equal_prop(actual.float64, expected.float64, 0)
5656
assert_equal_prop(actual.float32, expected.float32, 0)
5757
assert_equal_prop(actual.bytes, expected.bytes, b'')
58-
assert_equal_prop_vector(actual.ints, expected.ints, np.array([0]))
59-
assert_equal_prop_vector(actual.longs, expected.longs, np.array([0]))
60-
assert_equal_prop_vector(actual.floats, expected.floats, np.array([0]))
61-
assert_equal_prop_vector(actual.doubles, expected.doubles, np.array([0]))
58+
assert_equal_prop_vector(actual.ints, expected.ints, np.array([]))
59+
assert_equal_prop_vector(actual.longs, expected.longs, np.array([]))
60+
assert_equal_prop_vector(actual.floats, expected.floats, np.array([]))
61+
assert_equal_prop_vector(actual.doubles, expected.doubles, np.array([]))
6262
assert_equal_prop_list(actual.ints_list, expected.ints_list, [])
6363
assert_equal_prop_list(actual.longs_list, expected.longs_list, [])
6464
assert_equal_prop_list(actual.floats_list, expected.floats_list, [])

0 commit comments

Comments
 (0)