Skip to content

Commit 4cad3f1

Browse files
cbrnrCopilot
andcommitted
Address memory efficiency issue
Co-authored-by: Copilot <copilot@github.com>
1 parent 4f11945 commit 4cad3f1

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

mne/io/base.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3239,31 +3239,26 @@ def concatenate_raws(
32393239
on_mismatch=on_mismatch,
32403240
)
32413241

3242-
# check if all raws have the same type
3243-
mixed_types = not all(type(r) is type(raws[0]) for r in raws[1:])
3244-
if mixed_types:
3245-
# preload all data before concatenating different Raw types
3246-
for r in raws:
3247-
if not r.preload:
3248-
r.load_data()
3249-
preload = True
3250-
32513242
if events_list is not None:
32523243
if len(events_list) != len(raws):
32533244
raise ValueError(
32543245
"`raws` and `event_list` are required to be of the same length"
32553246
)
32563247
first, last = zip(*[(r.first_samp, r.last_samp) for r in raws])
32573248
events = concatenate_events(events_list, first, last)
3258-
raws[0].append(raws[1:], preload)
32593249

3260-
if mixed_types:
3250+
if not all(type(r) is type(raws[0]) for r in raws[1:]):
32613251
from .array import RawArray
32623252

3263-
out = RawArray(raws[0]._data, raws[0].info, first_samp=raws[0].first_samp)
3264-
out.set_annotations(raws[0].annotations)
3265-
else:
3266-
out = raws[0]
3253+
raws = list(raws) # local copy of list
3254+
if not raws[0].preload:
3255+
raws[0].load_data()
3256+
annotations = raws[0].annotations
3257+
raws[0] = RawArray(raws[0]._data, raws[0].info, first_samp=raws[0].first_samp)
3258+
raws[0].set_annotations(annotations)
3259+
preload = True
3260+
raws[0].append(raws[1:], preload)
3261+
out = raws[0]
32673262

32683263
if events_list is None:
32693264
return out

0 commit comments

Comments
 (0)