Skip to content

Commit

Permalink
Fix a small bug in merge_arrs
Browse files Browse the repository at this point in the history
  • Loading branch information
dachengx committed Nov 18, 2024
1 parent 8389ea6 commit 7df8daa
Showing 1 changed file with 6 additions and 3 deletions.
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

0 comments on commit 7df8daa

Please sign in to comment.