diff --git a/pydrepr/drepr/outputs/array_backend/array_predicate.py b/pydrepr/drepr/outputs/array_backend/array_predicate.py index aaf679d..64e3fdb 100644 --- a/pydrepr/drepr/outputs/array_backend/array_predicate.py +++ b/pydrepr/drepr/outputs/array_backend/array_predicate.py @@ -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']: diff --git a/pydrepr/drepr/version.py b/pydrepr/drepr/version.py index e026c11..718b6fe 100644 --- a/pydrepr/drepr/version.py +++ b/pydrepr/drepr/version.py @@ -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! diff --git a/pydrepr/tests/drepr/outputs/test_get_data_as_ndarray.py b/pydrepr/tests/drepr/outputs/test_get_data_as_ndarray.py index 20a3bf3..6f7251d 100644 --- a/pydrepr/tests/drepr/outputs/test_get_data_as_ndarray.py +++ b/pydrepr/tests/drepr/outputs/test_get_data_as_ndarray.py @@ -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 @@ -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 diff --git a/version_manager.py b/version_manager.py index 01be539..f664713 100644 --- a/version_manager.py +++ b/version_manager.py @@ -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"