Skip to content

Commit

Permalink
And store interface arrays as well
Browse files Browse the repository at this point in the history
  • Loading branch information
cmutel committed Feb 3, 2021
1 parent 50ddf0a commit a64eb92
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
14 changes: 11 additions & 3 deletions bw_processing/datapackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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",
Expand All @@ -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:
Expand Down
Binary file modified tests/fixtures/test-fixture.zip
Binary file not shown.
11 changes: 10 additions & 1 deletion tests/fixtures/tfd/datapackage.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions tests/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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",
Expand All @@ -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:
Expand Down

0 comments on commit a64eb92

Please sign in to comment.