-
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
fix: change primitive_policy
to allow converting Numpy arrays
#3375
Open
ianna
wants to merge
6
commits into
main
Choose a base branch
from
3373-cannot-add-array-to-dataframe
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+91
−1
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ianna
commented
Jan 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is what happened with "forbid" primitive policy:
def test_add_numpy():
d_data = {
'x' : numpy.array([1, 2, 3]),
'y' : numpy.array([4, 5, 6]),
}
rdf = RDF.MakeNumpyDataFrame(d_data)
rdf = rdf.Define('z', 'ROOT::RVec<int>({1, 2, 3})')
rdf = rdf.Define('w', 'true')
arr_val = numpy.array([10, 20, 30])
> rdf = add_numpy_column(rdf, arr_val, 'values')
arr_val = array([10, 20, 30])
d_data = {'x': array([1, 2, 3]), 'y': array([4, 5, 6])}
rdf = <cppyy.gbl.ROOT.RDF.RInterface<ROOT::Detail::RDF::RLoopManager,void> object at 0x7fe19e4605c0>
tests/test_3373_rdataframe.py:85:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/test_3373_rdataframe.py:69: in add_numpy_column
rdf = ak.to_rdataframe(d_data)
arr_val = array([10, 20, 30])
col = 'z'
d_data = {'values': array([10, 20, 30]),
'w': <Array [True, True, True] type='3 * bool'>,
'x': <Array [1, 2, 3] type='3 * int64'>,
'y': <Array [4, 5, 6] type='3 * int64'>,
'z': <Array [[1, 2, 3], [1, 2, 3], [1, 2, 3]] type='3 * var * int32'>}
data = <Array [{w: True, x: 1, y: 4, ...}, ..., {...}] type='3 * {w: bool, x: int6...'>
l_col = ['w', 'x', 'y', 'z']
l_col_org = ['w', 'x', 'y', 'z']
name = 'values'
rdf = <cppyy.gbl.ROOT.RDF.RInterface<ROOT::Detail::RDF::RLoopManager,void> object at 0x7fe19e4605c0>
v_col_org = <cppyy.gbl.std.vector<string> object at 0x7fe19e455620>
src/awkward/_dispatch.py:38: in dispatch
with OperationErrorContext(name, args, kwargs):
args = ({'values': array([10, 20, 30]),
'w': <Array [True, True, True] type='3 * bool'>,
'x': <Array [1, 2, 3] type='3 * int64'>,
'y': <Array [4, 5, 6] type='3 * int64'>,
'z': <Array [[1, 2, 3], [1, 2, 3], [1, 2, 3]] type='3 * var * int32'>},)
array_like = array([10, 20, 30])
array_likes = dict_values([<Array [True, True, True] type='3 * bool'>, <Array [1, 2, 3] type='3 * int64'>, <Array [4, 5, 6] type='3 * int64'>, <Array [[1, 2, 3], [1, 2, 3], [1, 2, 3]] type='3 * var * int32'>, array([10, 20, 30])])
dispatch = <function to_rdataframe at 0x14e033f40>
func = <function to_rdataframe at 0x14e033eb0>
gen_or_result = <generator object to_rdataframe at 0x14e12f060>
kwargs = {}
name = 'ak.to_rdataframe'
src/awkward/_errors.py:80: in __exit__
raise self.decorate_exception(exception_type, exception_value)
exception_type = <class 'AssertionError'>
exception_value = AssertionError()
self = <awkward._errors.OperationErrorContext object at 0x16a08eec0>
traceback = <traceback object at 0x16a0d2980>
src/awkward/_dispatch.py:64: in dispatch
next(gen_or_result)
args = ({'values': array([10, 20, 30]),
'w': <Array [True, True, True] type='3 * bool'>,
'x': <Array [1, 2, 3] type='3 * int64'>,
'y': <Array [4, 5, 6] type='3 * int64'>,
'z': <Array [[1, 2, 3], [1, 2, 3], [1, 2, 3]] type='3 * var * int32'>},)
array_like = array([10, 20, 30])
array_likes = dict_values([<Array [True, True, True] type='3 * bool'>, <Array [1, 2, 3] type='3 * int64'>, <Array [4, 5, 6] type='3 * int64'>, <Array [[1, 2, 3], [1, 2, 3], [1, 2, 3]] type='3 * var * int32'>, array([10, 20, 30])])
dispatch = <function to_rdataframe at 0x14e033f40>
func = <function to_rdataframe at 0x14e033eb0>
gen_or_result = <generator object to_rdataframe at 0x14e12f060>
kwargs = {}
name = 'ak.to_rdataframe'
src/awkward/operations/ak_to_rdataframe.py:53: in to_rdataframe
return _impl(
arrays = {'values': array([10, 20, 30]),
'w': <Array [True, True, True] type='3 * bool'>,
'x': <Array [1, 2, 3] type='3 * int64'>,
'y': <Array [4, 5, 6] type='3 * int64'>,
'z': <Array [[1, 2, 3], [1, 2, 3], [1, 2, 3]] type='3 * var * int32'>}
flatlist_as_rvec = True
src/awkward/operations/ak_to_rdataframe.py:77: in _impl
layouts[name] = ak.operations.ak_to_layout._impl(
array = array([10, 20, 30])
arrays = {'values': array([10, 20, 30]),
'w': <Array [True, True, True] type='3 * bool'>,
'x': <Array [1, 2, 3] type='3 * int64'>,
'y': <Array [4, 5, 6] type='3 * int64'>,
'z': <Array [[1, 2, 3], [1, 2, 3], [1, 2, 3]] type='3 * var * int32'>}
awkward = <module 'awkward' from '/Users/yana/Projects/IS3373/awkward/src/awkward/__init__.py'>
flatlist_as_rvec = True
layouts = {'w': <NumpyArray dtype='bool' len='3'>[ True True True]</NumpyArray>,
'x': <NumpyArray dtype='int64' len='3'>[1 2 3]</NumpyArray>,
'y': <NumpyArray dtype='int64' len='3'>[4 5 6]</NumpyArray>,
'z': <ListOffsetArray len='3'>
<offsets><Index dtype='int64' len='4'>
[0 3 6 9]
</Index></offsets>
<content><NumpyArray dtype='int32' len='9'>[1 2 3 1 2 3 1 2 3]</NumpyArray></content>
</ListOffsetArray>}
length = 3
name = 'values'
src/awkward/operations/ak_to_layout.py:184: in _impl
return _handle_array_like(
allow_record = False
allow_unknown = False
none_policy = 'error'
obj = array([10, 20, 30])
primitive_policy = 'forbid'
promoted_layout = <NumpyArray dtype='int64' len='3'>[10 20 30]</NumpyArray>
regulararray = True
string_policy = 'as-characters'
use_from_iter = True
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
obj = array([10, 20, 30]), layout = <NumpyArray dtype='int64' len='3'>[10 20 30]</NumpyArray>
def _handle_array_like(obj, layout, *, primitive_policy):
> assert primitive_policy in ("pass-through", "promote", "error")
E AssertionError
E
E
E See if this has been reported at https://github.com/scikit-hep/awkward/issues
layout = <NumpyArray dtype='int64' len='3'>[10 20 30]</NumpyArray>
obj = array([10, 20, 30])
primitive_policy = 'forbid'
src/awkward/operations/ak_to_layout.py:140: AssertionError
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #3373