Skip to content

merge_arrs might overwrite fields unintended #929

@dachengx

Description

@dachengx

strax/strax/utils.py

Lines 204 to 207 in 8389ea6

result = np.zeros(n, dtype=dtype)
for arr in arrs:
for fn in arr.dtype.names:
result[fn] = arr[fn]

If you have two chunks, say a and b then you want to merge them, the result depends on the order of these two variables.

import numpy as np
import strax


n = 3
a = np.empty(n, dtype=strax.time_fields)
a['time'] = range(n)
b = np.empty(n, dtype=strax.time_fields)
b['time'] = a['time'][::-1]

print(a['time'])
print(b['time'])
print(strax.merge_arrs([a, b])['time'])

output:

[0 1 2]
[2 1 0]
[2 1 0]

at least a warning should be shown in such cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions