Skip to content

Commit 8f75214

Browse files
authored
Fix a small bug in merge_arrs (#930)
1 parent 8389ea6 commit 8f75214

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

strax/utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,12 @@ def merged_dtype(dtypes):
175175

176176

177177
@export
178-
def merge_arrs(arrs, dtype=None):
178+
def merge_arrs(arrs, dtype=None, replacing=False):
179179
"""Merge structured arrays of equal length. On field name collisions, data from later arrays is
180180
kept.
181181
182+
replacing=True is usually used when you want to convert arrs into a new dtype
183+
182184
If you pass one array, it is returned without copying.
183185
TODO: hmm... inconsistent
184186
@@ -187,7 +189,7 @@ def merge_arrs(arrs, dtype=None):
187189
"""
188190
if not len(arrs):
189191
raise RuntimeError("Cannot merge 0 arrays")
190-
if len(arrs) == 1:
192+
if len(arrs) == 1 and not replacing:
191193
return arrs[0]
192194

193195
n = len(arrs[0])
@@ -204,7 +206,8 @@ def merge_arrs(arrs, dtype=None):
204206
result = np.zeros(n, dtype=dtype)
205207
for arr in arrs:
206208
for fn in arr.dtype.names:
207-
result[fn] = arr[fn]
209+
if fn in result.dtype.names:
210+
result[fn] = arr[fn]
208211
return result
209212

210213

0 commit comments

Comments
 (0)