diff --git a/bw_processing/datapackage.py b/bw_processing/datapackage.py index 40d65e2..ad1c3f5 100644 --- a/bw_processing/datapackage.py +++ b/bw_processing/datapackage.py @@ -114,7 +114,7 @@ def get_resource(self, name_or_index: Union[str, int]) -> (Any, dict): obj = self.data[index]() self.data[index] = obj - self._cache[name_or_index] = self.data[index], self.resources[index] + self._cache[name_or_index] = (self.data[index], self.resources[index]) return self._cache[name_or_index] def filter_by_attribute(self, key: str, value: Any) -> "FilteredDatapackage": @@ -604,8 +604,6 @@ def add_dynamic_array( ) name = self._prepare_name(name) - # Do something with dynamic vector - self._add_numpy_array_resource( array=load_bytes(indices_array), name=name + ".indices", @@ -622,6 +620,16 @@ def add_dynamic_array( **kwargs, ) + self.data.append(interface) + resource = { + "profile": "interface", + "name": name + ".data", + "group": name, + "kind": "data", + } + resource.update(**kwargs) + self.resources.append(resource) + def add_csv_metadata( self, *, dataframe: pd.DataFrame, valid_for: list, name: str = None, **kwargs ) -> None: diff --git a/tests/fixtures/test-fixture.zip b/tests/fixtures/test-fixture.zip index af7f892..c2d751c 100644 Binary files a/tests/fixtures/test-fixture.zip and b/tests/fixtures/test-fixture.zip differ diff --git a/tests/fixtures/tfd/datapackage.json b/tests/fixtures/tfd/datapackage.json index c8caf0c..2921d47 100644 --- a/tests/fixtures/tfd/datapackage.json +++ b/tests/fixtures/tfd/datapackage.json @@ -167,6 +167,15 @@ "category": "array", "nrows": 3 }, + { + "profile": "interface", + "name": "sa-array-interface.data", + "group": "sa-array-interface", + "kind": "data", + "matrix": "sa_matrix", + "category": "array", + "nrows": 3 + }, { "profile": "data-resource", "mediatype": "text/csv", @@ -194,7 +203,7 @@ "valid_for": "sa-data-array" } ], - "created": "2021-02-03T12:36:32.895174Z", + "created": "2021-02-03T13:03:15.461858Z", "combinatorial": false, "sequential": false, "seed": null, diff --git a/tests/integration.py b/tests/integration.py index 8901227..aa8377b 100644 --- a/tests/integration.py +++ b/tests/integration.py @@ -107,7 +107,7 @@ def add_data(dp): def check_data(dp): - assert len(dp.resources) == len(dp.data) == 16 + assert len(dp.resources) == len(dp.data) == 17 d, _ = dp.get_resource("sa-data-array-json-parameters") assert d == ["a", "foo"] @@ -284,6 +284,15 @@ def check_metadata(dp, as_tuples=True): "path": "sa-array-interface.indices.npy", "group": "sa-array-interface", }, + { + "category": "array", + "group": "sa-array-interface", + "kind": "data", + "matrix": "sa_matrix", + "name": "sa-array-interface.data", + "nrows": 3, + "profile": "interface", + }, { "profile": "data-resource", "mediatype": "text/csv", @@ -307,7 +316,7 @@ def check_metadata(dp, as_tuples=True): }, ] expected_as_list = deepcopy(expected) - expected_as_list[13]["valid_for"][0] = list(expected_as_list[13]["valid_for"][0]) + expected_as_list[14]["valid_for"][0] = list(expected_as_list[14]["valid_for"][0]) if as_tuples: assert dp.metadata["resources"] == expected else: