Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

normalize_per_cell raises numpy.core._exceptions.UFuncTypeError #2500

Closed
2 of 3 tasks
scottgigante-immunai opened this issue Jun 5, 2023 · 5 comments
Closed
2 of 3 tasks

Comments

@scottgigante-immunai
Copy link

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of scanpy.
  • (optional) I have confirmed this bug exists on the master branch of scanpy.

Minimal code sample (that we can copy&paste without having any data)

import numpy as np
import anndata as ad
import scanpy as sc

adata = ad.AnnData(np.random.poisson(0.2, (100, 200)))
sc.pp.normalize_per_cell(adata, 1e6)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/scottgigante/envs/immunaISR/lib/python3.8/site-packages/scanpy/preprocessing/_simple.py", line 527, in normalize_per_cell
    normalize_per_cell(adata.X, counts_per_cell_after, counts_per_cell)
  File "/Users/scottgigante/envs/immunaISR/lib/python3.8/site-packages/scanpy/preprocessing/_simple.py", line 562, in normalize_per_cell
    counts_per_cell /= counts_per_cell_after
numpy.core._exceptions.UFuncTypeError: Cannot cast ufunc 'divide' output from dtype('float64') to dtype('int64') with casting rule 'same_kind'

Versions

-----
anndata     0.9.1
scanpy      1.9.3
-----
PIL                 9.5.0
cffi                1.15.1
cloudpickle         2.2.1
cycler              0.10.0
cython_runtime      NA
dateutil            2.8.2
defusedxml          0.7.1
dill                0.3.6
google              NA
h5py                3.8.0
importlib_resources NA
joblib              1.3.0.dev0
kiwisolver          1.4.4
llvmlite            0.40.0
matplotlib          3.7.1
mpl_toolkits        NA
mpmath              1.3.0
natsort             8.3.1
numba               0.57.0
numpy               1.24.3
packaging           23.1
pandas              2.0.2
psutil              5.9.5
pyarrow             12.0.0
pyparsing           3.0.9
pytz                2023.3
scipy               1.10.1
session_info        1.0.0
six                 1.16.0
sklearn             1.2.2
sympy               1.11.1
threadpoolctl       3.1.0
torch               2.0.0
tqdm                4.65.0
typing_extensions   NA
yaml                6.0
zipp                NA
-----
Python 3.8.10 (v3.8.10:3d8993a744, May  3 2021, 08:55:58) [Clang 6.0 (clang-600.0.57)]
macOS-10.16-x86_64-i386-64bit
-----
Session information updated at 2023-06-05 12:34
@scottgigante-immunai scottgigante-immunai changed the title normalize_per_cell raises numpy.core._exceptions.UFuncTypeError: Cannot cast ufunc 'divide' output from dtype('float64') to dtype('int64') with casting rule 'same_kind' normalize_per_cell raises numpy.core._exceptions.UFuncTypeError Jun 5, 2023
@scottgigante-immunai
Copy link
Author

Workaround:

adata.X = adata.X.astype(np.float64)
sc.pp.normalize_per_cell(adata, 1e6)

@flying-sheep
Copy link
Member

please use normalize_total instead

image

@flying-sheep flying-sheep closed this as not planned Won't fix, can't repro, duplicate, stale Jun 7, 2023
@scottgigante-immunai
Copy link
Author

scottgigante-immunai commented Jun 7, 2023 via email

@flying-sheep
Copy link
Member

I had the same thought and opened #2505 to track that!

@scottgigante-immunai
Copy link
Author

scottgigante-immunai commented Jun 7, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants