anndata icon indicating copy to clipboard operation
anndata copied to clipboard

Large float converted to inf during adata creation

Open Hrovatin opened this issue 2 years ago • 2 comments

When adding large numbers to X I get adata with inf value:

y=np.array(2.07547187e+114).reshape(1,1)
y
Out[72]: array([[2.07547187e+114]])
sc.AnnData(y)
Out[73]: AnnData object with n_obs × n_vars = 1 × 1
sc.AnnData(y).X
Out[74]: array([[inf]], dtype=float32)
sc.AnnData(y).X[0,0]==np.inf
Out[76]: True

Hrovatin avatar Mar 09 '22 13:03 Hrovatin

Thanks for the report.

I think you'll be able to get around this by passing:

sc.AnnData(y, dtype=y.dtype)

for the next version, but this down casting won't happen anymore in 0.9.

I'm not sure if there's a great way to error for this specific case, as .astype(..., casting="safe") will error in many more cases.


Do you have a specific use case here? E.g. did this occur during an analysis?

I'm trying to figure out how bad this is.

ivirshup avatar Mar 09 '22 15:03 ivirshup

I was generating random data for testing - thus the extremely large numbers. never happened during analysis, at least not that I would know of.

Hrovatin avatar Mar 09 '22 15:03 Hrovatin

This issue has been automatically marked as stale because it has not had recent activity. Please add a comment if you want to keep the issue open. Thank you for your contributions!

github-actions[bot] avatar Aug 15 '23 02:08 github-actions[bot]

Fixed since 0.9.0!

flying-sheep avatar Aug 18 '23 06:08 flying-sheep