Skip to content

Commit 5ec40eb

Browse files
version is not optional and convert_ids function when target_version is provided in unwrangle
1 parent bddaa9b commit 5ec40eb

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

imas/wrangler.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import awkward as ak
33
import numpy as np
44
from . import IDSFactory
5+
from .ids_convert import convert_ids
56
from .ids_toplevel import IDSToplevel
67
from .backends.netcdf.ids_tensorizer import IDSTensorizer
78

@@ -33,7 +34,7 @@ def recursively_put(location, value, ids):
3334
return ids
3435

3536

36-
def wrangle(flat: Dict, source_version="3.41.0") -> Dict[str, IDSToplevel]:
37+
def wrangle(flat: Dict, source_version: str) -> Dict[str, IDSToplevel]:
3738
wrangled = {}
3839
factory = IDSFactory(source_version)
3940
for key in flat:
@@ -55,13 +56,18 @@ def split_location_across_ids(locations: List[str]) -> Dict[str, List[str]]:
5556

5657

5758
def unwrangle(
58-
locations: List[str], ids_dict: Dict[str, IDSToplevel], target_version="3.41.0"
59+
locations: List[str],
60+
ids_dict: Dict[str, IDSToplevel],
61+
target_version: str | None = None,
5962
) -> Tuple[Dict[str, ak.Array | np.ndarray], List[str]]:
6063
flat = {}
6164
ids_locations = split_location_across_ids(locations)
6265
failed_locations = []
6366
for key in ids_locations:
64-
tensorizer = IDSTensorizer(ids_dict[key], ids_locations[key])
67+
ids = ids_dict[key]
68+
if target_version is not None:
69+
ids = convert_ids(ids, target_version)
70+
tensorizer = IDSTensorizer(ids, ids_locations[key])
6571
tensorizer.include_coordinate_paths()
6672
tensorizer.collect_filled_data()
6773
tensorizer.determine_data_shapes()

0 commit comments

Comments
 (0)