From d18f600a0b7392d2bf118b695c894324de8c4eb7 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Mon, 16 Dec 2024 10:48:57 -0500 Subject: [PATCH 1/3] Stop using numpy.object, deprecated in 1.20 and later removed It was just an alias for the built-in object, so use that instead. --- klusta/traces/spikedetekt.py | 6 +++--- klusta/traces/store.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/klusta/traces/spikedetekt.py b/klusta/traces/spikedetekt.py index 829da1b..5b4fe6e 100644 --- a/klusta/traces/spikedetekt.py +++ b/klusta/traces/spikedetekt.py @@ -69,7 +69,7 @@ def _split_spikes(groups, idx=None, **arrs): def _array_list(arrs): - out = np.empty((len(arrs),), dtype=np.object) + out = np.empty((len(arrs),), dtype=object) out[:] = arrs return out @@ -385,10 +385,10 @@ def extract_spikes(self, components, traces_f, # groups). waveforms = _array_list(waveforms) assert waveforms.shape == (n_spikes,) - assert waveforms.dtype == np.object + assert waveforms.dtype == object masks = _array_list(masks) - assert masks.dtype == np.object + assert masks.dtype == object assert masks.shape == (n_spikes,) # Reorder the spikes. diff --git a/klusta/traces/store.py b/klusta/traces/store.py index 985907f..81e2488 100644 --- a/klusta/traces/store.py +++ b/klusta/traces/store.py @@ -97,7 +97,7 @@ def store(self, data=None, **kwargs): dtype = data.dtype if not data.size: return - assert dtype != np.object + assert dtype != object np.save(path, data) # debug("Store {}.".format(path)) From af32fe74d64b64345c4ec0531d44c39804ea2817 Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Mon, 16 Dec 2024 10:54:09 -0500 Subject: [PATCH 2/3] Stop using numpy.int, deprecated in 1.20 and later removed It was just an alias for the built-in int, so use that instead. --- klusta/traces/tests/test_spikedetekt.py | 2 +- klusta/utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/klusta/traces/tests/test_spikedetekt.py b/klusta/traces/tests/test_spikedetekt.py index 140e53f..15ae33b 100644 --- a/klusta/traces/tests/test_spikedetekt.py +++ b/klusta/traces/tests/test_spikedetekt.py @@ -46,7 +46,7 @@ def test_relative_channels(): def test_split_spikes(): - groups = np.zeros(10, dtype=np.int) + groups = np.zeros(10, dtype=int) groups[1::2] = 1 idx = np.ones(10, dtype=np.bool) diff --git a/klusta/utils.py b/klusta/utils.py index a21bfad..d81ce2c 100644 --- a/klusta/utils.py +++ b/klusta/utils.py @@ -75,7 +75,7 @@ def _index_of(arr, lookup): # values lookup = np.asarray(lookup, dtype=np.int32) m = (lookup.max() if len(lookup) else 0) + 1 - tmp = np.zeros(m + 1, dtype=np.int) + tmp = np.zeros(m + 1, dtype=int) # Ensure that -1 values are kept. tmp[-1] = -1 if len(lookup): From 8ba0eaee6cfc2d8bcf82519cb6f70e3de741ca3c Mon Sep 17 00:00:00 2001 From: "Benjamin A. Beasley" Date: Mon, 16 Dec 2024 14:33:59 -0500 Subject: [PATCH 3/3] Replace numpy.bool with numpy.bool_ In older numpy releases, numpy.bool was the same as Python bool. This was deprecated in 1.20 and later removed for 1.x, then the name numpy.bool was reintroduced in numpy 2.x as an alias for numpy.bool_, a Boolean value stored as a byte. By using numpy.bool_, we get the same data type on all Python versions. --- klusta/traces/detect.py | 4 ++-- klusta/traces/spikedetekt.py | 2 +- klusta/traces/tests/test_spikedetekt.py | 2 +- klusta/traces/waveform.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/klusta/traces/detect.py b/klusta/traces/detect.py index 11fe93d..5425820 100644 --- a/klusta/traces/detect.py +++ b/klusta/traces/detect.py @@ -355,8 +355,8 @@ def __init__(self, probe_adjacency_list=None, join_size=None, self._channels_per_group = channels_per_group def __call__(self, weak_crossings=None, strong_crossings=None): - weak_crossings = np.asarray(weak_crossings, np.bool) - strong_crossings = np.asarray(strong_crossings, np.bool) + weak_crossings = np.asarray(weak_crossings, np.bool_) + strong_crossings = np.asarray(strong_crossings, np.bool_) all_channels = sorted([item for sublist in self._channels_per_group.values() for item in sublist]) diff --git a/klusta/traces/spikedetekt.py b/klusta/traces/spikedetekt.py index 5b4fe6e..9d87f6f 100644 --- a/klusta/traces/spikedetekt.py +++ b/klusta/traces/spikedetekt.py @@ -49,7 +49,7 @@ def _split_spikes(groups, idx=None, **arrs): } groups = np.asarray(groups) if idx is not None: - assert idx.dtype == np.bool + assert idx.dtype in (bool, np.bool_) n_spikes_chunk = np.sum(idx) # First, remove the overlapping bands. groups = groups[idx] diff --git a/klusta/traces/tests/test_spikedetekt.py b/klusta/traces/tests/test_spikedetekt.py index 15ae33b..e6633e8 100644 --- a/klusta/traces/tests/test_spikedetekt.py +++ b/klusta/traces/tests/test_spikedetekt.py @@ -49,7 +49,7 @@ def test_split_spikes(): groups = np.zeros(10, dtype=int) groups[1::2] = 1 - idx = np.ones(10, dtype=np.bool) + idx = np.ones(10, dtype=np.bool_) idx[0] = False idx[-1] = False diff --git a/klusta/traces/waveform.py b/klusta/traces/waveform.py index 1ddb7b4..17b1027 100644 --- a/klusta/traces/waveform.py +++ b/klusta/traces/waveform.py @@ -110,7 +110,7 @@ def masks(self, data_t, wave, comp): s_min = comp.s_min # Binary mask. shape: (nc,) - masks_bin = np.zeros(nc, dtype=np.bool) + masks_bin = np.zeros(nc, dtype=np.bool_) masks_bin[np.unique(comp_ch)] = 1 # Find the peaks (relative to the start of the chunk). shape: (nc,)