Skip to content

Add the ability to convert from/to awkward array#108

Open
AreWeDreaming wants to merge 14 commits intoiterorganization:developfrom
AreWeDreaming:awkward_array_support
Open

Add the ability to convert from/to awkward array#108
AreWeDreaming wants to merge 14 commits intoiterorganization:developfrom
AreWeDreaming:awkward_array_support

Conversation

@AreWeDreaming
Copy link

@AreWeDreaming AreWeDreaming commented Mar 17, 2026

The tests (imas/test/test_wrangle.py) that I have designed are passing now.
The wrangler.py adds two functions, wrangle and unwrangle.

  • The wrangle method takes the flat representation of the data and wrangles into the nested IDS.
  • The unwrangle method takes a dictionary of ids and uses the IDSTensorizer to flatten out a defined list of entries.

- Wrangling works
- Unwrangling awkward data needs work
@AreWeDreaming
Copy link
Author

I am holding off on running black to keep the diff clean

from typing import List, Tuple

import numpy
import awkward as ak
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed from here and moved to actual usage..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved awkwardization into the wrangler.py

if hdf5_dim == 0:
return self.filled_data[path][()].value
else:
return ak.Array(self.recursively_convert_to_list(path, tuple(), shape[:hdf5_dim], 0))
Copy link
Collaborator

@prasad-sawantdesai prasad-sawantdesai Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if awkward is available

            try:
                import awkward as ak
            except ImportError as exc:
                raise ImportError(
                    "awkward-array is required"
                    "Install it with: pip install imas-python[awkward]"
                ) from exc

Need to add awkward dependency in pyproject.toml

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied as suggested

imas/wrangler.py Outdated
return ids_locations

def unwrangle(
locations: List[str], ids_dict: Dict[str, IDSToplevel], version="3.41.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version is not used here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because I didn't know how to convert between IMAS versions. I would like to do to an automatic version transformation using this target version.

AreWeDreaming and others added 4 commits March 18, 2026 08:42
Handle version propagation more cleanly

Co-authored-by: Prasad <prasad.sawantdesai@gmail.com>
Remove preference for specific version

Co-authored-by: Prasad <prasad.sawantdesai@gmail.com>
failed_locations = []
for key in ids_locations:
ids = ids_dict[key]
if target_version is not None:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also should compare versions strings so we don't convert if we are already in the correct version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants