@@ -158,7 +158,7 @@ def _new_spiketrain(
158158 if annotations is None :
159159 annotations = {}
160160 obj = SpikeTrain (
161- signal = signal ,
161+ times = signal ,
162162 t_stop = t_stop ,
163163 units = units ,
164164 dtype = dtype ,
@@ -178,7 +178,7 @@ def _new_spiketrain(
178178 return obj
179179
180180
181- def normalize_times_array (times , units = None , dtype = None , copy = True ):
181+ def normalize_times_array (times , units = None , dtype = None , copy = None ):
182182 """
183183 Return a quantity array with the correct units.
184184 There are four scenarios:
@@ -192,6 +192,12 @@ def normalize_times_array(times, units=None, dtype=None, copy=True):
192192 In scenario C, we rescale the original array to match `units`
193193 In scenario D, we raise a ValueError
194194 """
195+
196+ if copy is not None :
197+ raise ValueError (
198+ "`copy` is now deprecated in Neo due to removal in NumPy 2.0 and will be removed in 0.15.0."
199+ )
200+
195201 if dtype is None :
196202 if not hasattr (times , "dtype" ):
197203 dtype = float
@@ -211,13 +217,8 @@ def normalize_times_array(times, units=None, dtype=None, copy=True):
211217 if times .dimensionality .items () == dim .items ():
212218 units = None # units will be taken from times, avoids copying
213219 else :
214- if not copy :
215- raise ValueError ("cannot rescale and return view" )
216- else :
217- # this is needed because of a bug in python-quantities
218- # see issue # 65 in python-quantities github
219- # remove this if it is fixed
220- times = times .rescale (dim )
220+ raise ValueError ("cannot rescale and return view" )
221+
221222
222223 # check to make sure the units are time
223224 # this approach is orders of magnitude faster than comparing the
@@ -239,7 +240,7 @@ class SpikeTrain(DataObject):
239240 times: quantity array 1D | numpy array 1D | list
240241 The times of each spike.
241242 t_stop: quantity scalar | numpy scalar |float
242- Time at which the SpikeTrain ended. This will be converted to thesame units as `times`.
243+ Time at which the SpikeTrain ended. This will be converted to the same units as `times`.
243244 This argument is required because it specifies the period of time over which spikes could have occurred.
244245 Note that :attr:`t_start` is highly recommended for the same reason.
245246 units: (quantity units) | None, default: None
@@ -740,7 +741,8 @@ def duplicate_with_new_data(self, signal, t_start=None, t_stop=None, waveforms=N
740741 else :
741742 units = pq .quantity .validate_dimensionality (units )
742743
743- new_st = self .__class__ (signal , t_start = t_start , t_stop = t_stop , waveforms = waveforms , units = units )
744+ signal = deepcopy (signal )
745+ new_st = SpikeTrain (signal , t_start = t_start , t_stop = t_stop , waveforms = waveforms , units = units )
744746 new_st ._copy_data_complement (self , deep_copy = deep_copy )
745747
746748 # Note: Array annotations are not copied here, because length of data could change
@@ -800,9 +802,24 @@ def time_shift(self, t_shift):
800802 New instance of a :class:`SpikeTrain` object starting at t_shift later than the
801803 original :class:`SpikeTrain` (the original :class:`SpikeTrain` is not modified).
802804 """
803- new_st = self .duplicate_with_new_data (
804- signal = self .times .view (pq .Quantity ) + t_shift , t_start = self .t_start + t_shift , t_stop = self .t_stop + t_shift
805- )
805+ # We need new to make a new SpikeTrain
806+ times = self .times .copy () + t_shift
807+ t_stop = self .t_stop + t_shift
808+ t_start = self .t_start + t_shift
809+ new_st = SpikeTrain (
810+ times = times ,
811+ t_stop = t_stop ,
812+ units = self .unit ,
813+ sampling_rate = self .sampling_rate ,
814+ t_start = t_start ,
815+ waveforms = self .waveforms ,
816+ left_sweep = self .left_sweep ,
817+ name = self .name ,
818+ file_origin = self .file_origin ,
819+ description = self .description ,
820+ array_annotations = deepcopy (self .array_annotations ),
821+ ** self .annotations ,
822+ )
806823
807824 # Here we can safely copy the array annotations since we know that
808825 # the length of the SpikeTrain does not change.
@@ -847,7 +864,7 @@ def merge(self, *others):
847864 raise MergeError ("Cannot merge signal with waveform and signal " "without waveform." )
848865 stack = np .concatenate ([np .asarray (st ) for st in all_spiketrains ])
849866 sorting = np .argsort (stack )
850- stack = stack [sorting ]
867+ sorted_stack = stack [sorting ]
851868
852869 kwargs = {}
853870
@@ -902,10 +919,10 @@ def merge(self, *others):
902919 kwargs .update (merged_annotations )
903920
904921 train = SpikeTrain (
905- stack ,
922+ sorted_stack ,
906923 units = self .units ,
907924 dtype = self .dtype ,
908- copy = False ,
925+ copy = None ,
909926 t_start = self .t_start ,
910927 t_stop = self .t_stop ,
911928 sampling_rate = self .sampling_rate ,
0 commit comments