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

Fix a small bug in merge_arrs #930

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions strax/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,12 @@ def merged_dtype(dtypes):


@export
def merge_arrs(arrs, dtype=None):
def merge_arrs(arrs, dtype=None, replacing=False):
"""Merge structured arrays of equal length. On field name collisions, data from later arrays is
kept.

replacing=True is usually used when you want to convert arrs into a new dtype

If you pass one array, it is returned without copying.
TODO: hmm... inconsistent

Expand All @@ -187,7 +189,7 @@ def merge_arrs(arrs, dtype=None):
"""
if not len(arrs):
raise RuntimeError("Cannot merge 0 arrays")
if len(arrs) == 1:
if len(arrs) == 1 and not replacing:
return arrs[0]

n = len(arrs[0])
Expand All @@ -204,7 +206,8 @@ def merge_arrs(arrs, dtype=None):
result = np.zeros(n, dtype=dtype)
for arr in arrs:
for fn in arr.dtype.names:
result[fn] = arr[fn]
if fn in result.dtype.names:
result[fn] = arr[fn]
return result


Expand Down