Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named axes in nested awkward arrays #3346

Open
kumarneelabh13 opened this issue Dec 16, 2024 · 1 comment
Open

Named axes in nested awkward arrays #3346

kumarneelabh13 opened this issue Dec 16, 2024 · 1 comment
Labels
feature New feature or request

Comments

@kumarneelabh13
Copy link

kumarneelabh13 commented Dec 16, 2024

Description of new feature

image
Axis names are lost when an awkward array with named axes is nested inside another awkward array. (Example attached)

Can awkward array preserve the named axes?

@kumarneelabh13 kumarneelabh13 added the feature New feature or request label Dec 16, 2024
@pfackeldey
Copy link
Collaborator

pfackeldey commented Dec 16, 2024

Hi @kumarneelabh13,

in order to preserve attrs (the metadata container that keeps track of named axis) you can use ak.zip instead:

awkward_array = ak.zip({
  "foo": ak.with_named_axis(ak.Array([1]), ("time",)),
  "bar": ak.Array([2]),
})
awkward_array.show(named_axis=True)
# axes: time:0
# [{foo: 1, bar: 2}]

This one will also make sure that you don't have named axis clashes:

awkward_array = ak.zip({
  "foo": ak.with_named_axis(ak.Array([1]), ("time",)),
  "bar": ak.with_named_axis(ak.Array([2]), ("space",))
})
# > ValueError: The named axes are incompatible. Got: time and space for positional axis 0

I'd say that for constructing record arrays it is usually preferred to use ak.zip instead of the ak.Array constructor. Can you confirm this @jpivarski ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants