Skip to content

Commit

Permalink
fix bugs in array_predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
Binh Vu committed Mar 8, 2020
1 parent a2bed4d commit 6be1b39
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions pydrepr/drepr/outputs/array_backend/array_predicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ def as_ndarray(self, index_predicates: List[Union['ArrayDataPredicate', 'ArrayOb
index_attr_positions[j].start = min(i, index_attr_positions[j].start)
index_attr_positions[j].end = max(i + 1, index_attr_positions[j].end)
data = np.transpose(data, new_axies)
# un-occupied dimensions should be collapse to 1 dimension (they always at the last)
last_un_occupied_dim = 0
if len(index_attr_positions) > 0:
last_un_occupied_dim = max((p.end for p in index_attr_positions)) + 1
if last_un_occupied_dim < len(data.shape) - 1:
shp = list(data.shape[:last_un_occupied_dim]) + [-1]
data = data.reshape(shp)
return PropDataNDArray(data, attr.nodata, index_attr_positions, [a.get_data() for a in index_attrs])

def o(self) -> Optional['LstArrayClass']:
Expand Down
2 changes: 1 addition & 1 deletion pydrepr/drepr/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "2.9.1" # ___PKG_VERSION___: DO NOT MODIFY the version here. Update it via version_manager.py!
__version__ = "2.9.2" # ___PKG_VERSION___: DO NOT MODIFY the version here. Update it via version_manager.py!
__engine_version__ = "1.0.8" # ___PKG_VERSION___: DO NOT MODIFY the version here. Update it via version_manager.py!
__engine_release_tag__ = "2.7" # ___PKG_VERSION___: DO NOT MODIFY the version here. Update it via version_manager.py!
2 changes: 2 additions & 0 deletions pydrepr/tests/drepr/outputs/test_get_data_as_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test_get_prop_as_ndarray(s01: List[BaseOutputSM], s02: List[BaseOutputSM], s
mint_geo = sm.ns("https://mint.isi.edu/geo")

for c in sm.c(mint.Variable):
assert c.p(rdf.value).as_ndarray([]).data.shape == (sum(1 for _ in c.iter_records()),)
data = c.p(rdf.value).as_ndarray([c.p(mint_geo.lat), c.p(mint_geo.long)])
assert len(data.index_props) == 2

Expand All @@ -68,4 +69,5 @@ def test_get_prop_as_ndarray(s01: List[BaseOutputSM], s02: List[BaseOutputSM], s
assert records[i].s(rdf.value) == data.data[i]
assert records[i].s(mint_geo.lat) == data.index_props[0][i]
assert records[i].s(mint_geo.long) == data.index_props[1][i]

assert len(array_values) == 0 and len(graph_values) == 0
2 changes: 1 addition & 1 deletion version_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# ================================================================================
# Note: update the version by changing variables before the `=...=` line
DREPR_PYLIB_VESRION = "2.9.1"
DREPR_PYLIB_VESRION = "2.9.2"
DREPR_ENGINE_VERSION = "1.0.8"
# this tag marks the release which contains the pre-built engine in it.
DREPR_ENGINE_RELEASE_TAG = "2.7"
Expand Down

0 comments on commit 6be1b39

Please sign in to comment.