Skip to content

Commit

Permalink
Fix pandas.__getitem__ warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
michalk8 committed Nov 2, 2023
1 parent 0f6fe72 commit fcc8114
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/cellrank/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/cellrank/estimators/terminal_states/_gpcca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/cellrank/pl/_heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions tests/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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))))
Expand All @@ -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

Expand Down

0 comments on commit fcc8114

Please sign in to comment.