Skip to content

Commit

Permalink
Don't pass dtype to AnnData
Browse files Browse the repository at this point in the history
  • Loading branch information
michalk8 committed Nov 2, 2023
1 parent 5490620 commit c679d6f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/cellrank/estimators/terminal_states/_gpcca.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ def plot_macrostate_composition(
cats_colors = _create_categorical_colors(len(self.adata.obs[key].cat.categories))
cat_color_mapper = dict(zip(self.adata.obs[key].cat.categories, cats_colors))
x_indices = np.arange(len(macrostates.cat.categories))
bottom = np.zeros_like(x_indices, dtype=np.float32)
bottom = np.zeros_like(x_indices, dtype=float)

width = min(1, max(0, width))
fig, ax = plt.subplots(figsize=figsize, dpi=dpi, tight_layout=True)
Expand Down Expand Up @@ -1155,7 +1155,7 @@ def _write_macrostates(
self._set("_coarse_stat_dist", value=stat_dist, shadow_only=True)
self._set(
obj=self.adata.uns, key=Key.uns.coarse(self.backward),
value=AnnData(tmat, obs=dists, dtype=float)
value=AnnData(tmat, obs=dists),
)
else:
for attr in ["_schur_vectors", "_schur_matrix", "_coarse_tmat", "_coarse_init_dist", "_coarse_stat_dist"]:
Expand Down
2 changes: 1 addition & 1 deletion src/cellrank/kernels/_precomputed_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _from_matrix(
# fmt: off
if adata is None:
logg.warning(f"Creating empty `AnnData` object of shape `{matrix.shape[0], 1}`")
adata = AnnData(sp.csr_matrix((matrix.shape[0], 1), dtype=np.float64))
adata = AnnData(sp.csr_matrix((matrix.shape[0], 1)))
super().__init__(adata)
self._backward: Optional[bool] = backward
self.transition_matrix = matrix.copy() if copy else matrix
Expand Down
6 changes: 3 additions & 3 deletions src/cellrank/kernels/_real_time_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def _restich_couplings(
for ix in range(len(blocks)):
index.extend(obs_names[ix])

tmp = AnnData(sp.bmat(blocks, format="csr"), dtype="float64")
tmp = AnnData(sp.bmat(blocks, format="csr"))
tmp.obs_names = index
tmp.var_names = index
tmp = tmp[self.adata.obs_names, :][:, self.adata.obs_names]
Expand Down Expand Up @@ -520,7 +520,7 @@ def _sparsify_couplings(
tmat = sp.csr_matrix(tmat, dtype=tmat.dtype)
tmat.data[tmat.data < thresh] = 0.0
tmat.eliminate_zeros()
couplings[key] = AnnData(tmat, obs=adata.obs, var=adata.var, dtype=tmat.dtype)
couplings[key] = AnnData(tmat, obs=adata.obs, var=adata.var)

return couplings if copy else None

Expand Down Expand Up @@ -579,7 +579,7 @@ def assert_same(expected: Sequence[Any], actual: Sequence[Any], msg: Optional[st
def _coupling_to_adata(self, src: Any, tgt: Any, coupling: Coupling_t) -> AnnData:
"""Convert the coupling to :class:`~anndata.AnnData`."""
if not isinstance(coupling, AnnData):
coupling = AnnData(X=coupling, dtype=coupling.dtype)
coupling = AnnData(X=coupling)
coupling.obs_names = np.asarray(self.adata.obs_names)[self.time == src]
coupling.var_names = np.asarray(self.adata.obs_names)[self.time == tgt]

Expand Down
2 changes: 1 addition & 1 deletion src/cellrank/pl/_aggregate_fate_probs.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def plot_violin_no_cluster_key():
kwargs["rotation"] = xrot

data = np.ravel(probs.X.T)[..., None]
tmp = AnnData(sp.csr_matrix(data.shape, dtype=data.dtype), dtype=data.dtype)
tmp = AnnData(sp.csr_matrix(data.shape, dtype=data.dtype))
tmp.obs["fate probability"] = data
tmp.obs[term_states] = (
pd.Series(np.concatenate([[f"{direction.lower()} {n}"] * adata.n_obs for n in probs.names]))
Expand Down

0 comments on commit c679d6f

Please sign in to comment.