From 2ec408a7a830eb8dd60d610af5a681391fe17eaa Mon Sep 17 00:00:00 2001 From: marouenbg Date: Tue, 24 Mar 2026 19:00:29 -0400 Subject: [PATCH 1/2] Replace deprecated numpy tostring/fromstring with tobytes/frombuffer np.ndarray.tostring() was removed in numpy 2.3+. Replace all tostring()/fromstring() calls with tobytes()/frombuffer() which have identical behavior and are the supported API. Fixes netZoo/netZooPy#378 --- netZooPy/lioness/lioness.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/netZooPy/lioness/lioness.py b/netZooPy/lioness/lioness.py index b6b2ade2..0df5b5f5 100644 --- a/netZooPy/lioness/lioness.py +++ b/netZooPy/lioness/lioness.py @@ -412,16 +412,16 @@ def __lioness_loop(self, i): return(np.array([0])) else: if self.computing == "gpu" and i == 0: - self.total_lioness_network = np.fromstring( - np.transpose(lioness_network).tostring(), dtype=lioness_network.dtype + self.total_lioness_network = np.frombuffer( + np.transpose(lioness_network).tobytes(), dtype=lioness_network.dtype )[:,np.newaxis] elif self.computing == "gpu" and i != 0: self.total_lioness_network = np.column_stack( ( self.total_lioness_network, - np.fromstring( - np.transpose(lioness_network).tostring(), + np.frombuffer( + np.transpose(lioness_network).tobytes(), dtype=lioness_network.dtype, ), ) @@ -467,9 +467,9 @@ def __par_lioness_loop(self, i, output, online_coexpression=None): # TODO: why this? Should we remove it? # if i == 0: - # self.total_lioness_network = np.fromstring(np.transpose(lioness_network).tostring(),dtype=lioness_network.dtype) + # self.total_lioness_network = np.frombuffer(np.transpose(lioness_network).tobytes(),dtype=lioness_network.dtype) # else: - # self.total_lioness_network=np.column_stack((self.total_lioness_network ,np.fromstring(np.transpose(lioness_network).tostring(),dtype=lioness_network.dtype))) + # self.total_lioness_network=np.column_stack((self.total_lioness_network ,np.frombuffer(np.transpose(lioness_network).tobytes(),dtype=lioness_network.dtype))) if self.ignore_final: return(np.array([0])) else: From 31d4ec2ffe413cbead03a5fe9182353abca11fd2 Mon Sep 17 00:00:00 2001 From: marouenbg Date: Tue, 24 Mar 2026 19:26:57 -0400 Subject: [PATCH 2/2] Fix pandas 4.x compatibility in cobra test and condor - test_cobra: use numpy array for mean computation instead of pandas Series integer access (KeyError: 0 with string column index) - condor: use .iloc for positional access on iterrows() Series (KeyError: 2 with string column labels) - condor: use ki.sum() instead of float(sum(ki)) to avoid TypeError with np.matrix column vectors in newer numpy --- netZooPy/condor/condor.py | 5 +++-- tests/test_cobra.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/netZooPy/condor/condor.py b/netZooPy/condor/condor.py index 0e755bd9..bc5e95c5 100644 --- a/netZooPy/condor/condor.py +++ b/netZooPy/condor/condor.py @@ -305,13 +305,14 @@ def matrices(self, c,resolution): # Computes weighted biadjacency matrix. A = np.matrix(np.zeros((p, q))) for edge in self.net.iterrows(): - A[gn[edge[1][1]], rg[edge[1][0]]] = edge[1][2] + row = edge[1] + A[gn[row.iloc[1]], rg[row.iloc[0]]] = row.iloc[2] # Computes node degrees for the nodesets. ki = A.sum(1) dj = A.sum(0) # Computes sum of edges and bimodularity matrix. - m = float(sum(ki)) + m = float(ki.sum()) B = A - resolution*((ki @ dj) / m) # d = self.index_dict diff --git a/tests/test_cobra.py b/tests/test_cobra.py index 2fe940fc..00e59e55 100644 --- a/tests/test_cobra.py +++ b/tests/test_cobra.py @@ -37,7 +37,8 @@ def test_cobra(): pd.testing.assert_frame_equal(G, G_gt, rtol=1e-10, check_exact=False) q = psi.shape[0] + X_mean = np.mean(X.to_numpy(), axis=0) for i in range(q): - C = Q.to_numpy().dot(np.mean(X, axis=0)[i] * np.diag(psi.to_numpy()[i, :])).dot(Q.to_numpy().T) - C_gt = Q_gt.to_numpy().dot(np.mean(X, axis=0)[i] * np.diag(psi_gt.to_numpy()[i, :])).dot(Q_gt.to_numpy().T) + C = Q.to_numpy().dot(X_mean[i] * np.diag(psi.to_numpy()[i, :])).dot(Q.to_numpy().T) + C_gt = Q_gt.to_numpy().dot(X_mean[i] * np.diag(psi_gt.to_numpy()[i, :])).dot(Q_gt.to_numpy().T) pd.testing.assert_frame_equal(pd.DataFrame(C), pd.DataFrame(C_gt), rtol=1e-10, check_exact=False)