-
Notifications
You must be signed in to change notification settings - Fork 89
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
Which ak.Array constructor signatures should be allowed? e.g. [np.array([1, 2, 3]), np.array([4, 5, 6, 7])] #146
Comments
The latest release and master are not far apart—usually there's no difference between them. About this error, you gave it a Python list of two NumPy arrays. That pattern isn't convertible to an array, but I suppose it could be. Do you want it to mean a regular array with shape ak.Array([[1, 2, 3], [4, 5, 6]]) (which gives you a jagged array) or ak.Array(np.array([[1, 2, 3], [4, 5, 6]])) (which gives you a regular array). It's not too early to submit bug reports like this. This constructor goes through awkward1.operations.convert.fromiter Check that and see if it's what you want. You might want to add another case, it a better error message. |
Thanks for the quick answer, as always! My MWE was a bit too minimal ;) I am dealing with differing array lengths and even nested structures, so wrapping it into a [ins] In [20]: a = ak.Array(np.array([[1,2,3], [3,4,5,6]]))
[ins] In [21]: a
Out[21]: ---------------------------------------------------------------------------
...
...
ValueError: Numpy format "O" cannot be expressed as a PrimitiveType But coming back to this |
Now that you've put different lengths into each subarray, it can't be a "normal" NumPy array and NumPy represents it with dtype ak.Array(np.array([[1,2,3], [3,4,5,6]])) can't be an allowed procedure—NumPy has already broken the data before we get to it. On the other hand, maybe what we should do with NumPy You're right that ak.Array(np.array([[1, 2, 3], [4, 5, 6]]) # internally calls fromnumpy is more lightweight than ak.Array([[1, 2, 3], [4, 5, 6]]) # internally calls fromiter The first casts the NumPy array (without even copying it, using fromnumpy) and the second iterates and performs type-inference on the fly (using fromiter). However, they result in different types: >>> ak.typeof(ak.Array(np.array([[1, 2, 3], [4, 5, 6]])))
2 * 3 * int64
>>> ak.typeof(ak.Array([[1, 2, 3], [4, 5, 6]]))
2 * var * int64 The first array has When I say, define what you'd like it to do, I mean open a PR and propose a behavior for a case that currently errors-out. If you want NumPy dtype |
Yes I agree ;) I will think about it. For numpy I'll walk through the internals of |
Let me know if you're still thinking about this. It's okay to come back to it later. |
Sorry for the late response: yes I am still thinking about it. Meanwhile I set up the dev environment and playing around with it and have more questions and ideas already 😉 I think in first place it would be nice if the |
One thing we should be careful to keep in mind is that If you want to follow this particular rabbit hole, the Python-side It goes straight into C++ (where iteration over the Python objects was considerably faster, even though they have to do the same Python introspection). It's here: I'm a little surprised that a NumPy array doesn't count as a I must have been assuming that it would when I wrote that. However, we can add an explicit test for Anything produced by |
The |
The specific issue you were asking about has been resolved, so I'll be closing this. >>> import awkward1 as ak
>>> import numpy as np
>>> ak.Array([[1, 2, 3], [4, 5, 6, 7]])
<Array [[1, 2, 3], [4, 5, 6, 7]] type='2 * var * int64'>
>>> ak.Array([np.array([1, 2, 3]), np.array([4, 5, 6, 7])])
<Array [[1, 2, 3], [4, 5, 6, 7]] type='2 * var * int64'> |
Thank you Jim! |
Maybe it's too early for such bug reports and I am also not using the latest
master
but0.1.137
from PyPI but I started migrating and discovered that nested Numpy arrays are causing issues, as seen here:The text was updated successfully, but these errors were encountered: