From fcc81144eda957e9ad1ba19524050c474227b958 Mon Sep 17 00:00:00 2001 From: Michal Klein <46717574+michalk8@users.noreply.github.com> Date: Thu, 2 Nov 2023 22:29:12 +0100 Subject: [PATCH] Fix `pandas.__getitem__` warnings --- src/cellrank/_utils/_utils.py | 2 +- src/cellrank/estimators/terminal_states/_gpcca.py | 2 +- src/cellrank/pl/_heatmap.py | 2 +- tests/_helpers.py | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cellrank/_utils/_utils.py b/src/cellrank/_utils/_utils.py index c3fffdbef..e4a0dbf64 100644 --- a/src/cellrank/_utils/_utils.py +++ b/src/cellrank/_utils/_utils.py @@ -1158,7 +1158,7 @@ def _series_from_one_hot_matrix( target_series = pd.Series(index=index, dtype="category") for vec, name in zip(membership.T, names): target_series = target_series.cat.add_categories(name) - target_series[np.where(vec)[0]] = name + target_series.iloc[np.where(vec)[0]] = name return target_series diff --git a/src/cellrank/estimators/terminal_states/_gpcca.py b/src/cellrank/estimators/terminal_states/_gpcca.py index c84b1c620..1dbc077a0 100644 --- a/src/cellrank/estimators/terminal_states/_gpcca.py +++ b/src/cellrank/estimators/terminal_states/_gpcca.py @@ -367,7 +367,7 @@ def predict_initial_states(self, n_states: int = 1, n_cells: int = 30, allow_ove if stat_dist is None: raise RuntimeError("No coarse-grained stationary distribution found.") - states = list(stat_dist[np.argsort(stat_dist)][:n_states].index) + states = list(stat_dist.iloc[np.argsort(stat_dist)][:n_states].index) return self.set_initial_states(states, n_cells=n_cells, allow_overlap=allow_overlap) @d.dedent diff --git a/src/cellrank/pl/_heatmap.py b/src/cellrank/pl/_heatmap.py index e458c8974..be49a7b84 100644 --- a/src/cellrank/pl/_heatmap.py +++ b/src/cellrank/pl/_heatmap.py @@ -178,7 +178,7 @@ def find_nearest(array: np.ndarray, value: float) -> int: return int(ix) series = series.sort_values(ascending=True) - return list(series[[find_nearest(series.values, v) for v in values]].index) + return list(series.iloc[[find_nearest(series.values, v) for v in values]].index) def subset_lineage(lname: str, rng: np.ndarray) -> np.ndarray: time_series = adata.obs[time_key] diff --git a/tests/_helpers.py b/tests/_helpers.py index 37cb8b8d3..e5a114078 100644 --- a/tests/_helpers.py +++ b/tests/_helpers.py @@ -56,7 +56,7 @@ def _rpy2_mgcv_not_installed() -> bool: def bias_knn( conn: sp.csr_matrix, - pseudotime: np.ndarray, + pseudotime: pd.Series, n_neighbors: int, k: int = 3, frac_to_keep: Optional[float] = None, @@ -72,7 +72,7 @@ def bias_knn( # get indices, values and current pseudo t row_data = conn[i, :].data row_ixs = conn[i, :].indices - current_t = pseudotime[i] + current_t = pseudotime.iloc[i] if frac_to_keep is not None: k_thresh = max(0, min(30, int(np.floor(len(row_data) * frac_to_keep)))) @@ -83,7 +83,7 @@ def bias_knn( cand_ixs = sorted_ixs[k_thresh:] # compare pseudotimes and set indices to zero - cand_t = pseudotime[cand_ixs] + cand_t = pseudotime.iloc[cand_ixs] rem_ixs = cand_ixs[cand_t < current_t] conn_biased[i, rem_ixs] = 0