Comments (11)
Sorry about the late response: yes, your .iloc
/.loc
analogy is correct. You'll find a similar behavior to anndata (without .iloc
/.loc
) also in numpy structured arrays. I'll add your analogy to the docs.
Thank you!
And, yes, we should also throw an error for the integer indexing. Leaving this open for now.
from anndata.
Just cause I feel like my current work-around is silly (converting the integer obs_names to strings), I was looking into why this is happening. Am I correct in thinking the assertion I'm triggering was added since indexing into an AnnData
object with a numeric is supposed to be positional, like pandas
.iloc
method, while indexing with a string/ categorical is supposed to behave like .loc
?
from anndata.
I added this warning when people try to work with non-string indices: 51be5d8.
from anndata.
Hi @falexwolf, @ivirshup ,
I was trying to use BBKNN and got this error when trying to concatenate different datasets (see here). Could you please clarify how you managed to fix that?
Thank you!
from anndata.
Sorry about this bug! It might be related to the objects having integer indices: we shouldn't have an error thrown, I guess. But previously, this was presumably inconsistent behavior. @flying-sheep, did you add the following line at some point to _normalize_index
, which triggers the error:
assert names.dtype != float and names.dtype != int, \
'Don’t call _normalize_index with non-categorical/string names'
from anndata.
am I missing something? AFAIK datasets still can’t have integer var_names
or obs_names
. else it’s impossible to distinguish if e.g. adata[0, :]
means adata[adata.obs_names == 0, :]
or adata[np.arange(adata.shape[0]) == 0, :]
.
from anndata.
Thank you for the clarification! I think this error was not thrown in scanpy 1.2.2 (for example here), but it does occur now (scanpy 1.3.6). I guess a solution could be to force the var_names
to string.
from anndata.
am I missing something? AFAIK datasets still can’t have integer var_names or obs_names.
@flying-sheep we never threw an error when people set non-string indices; so there will be objects out there that have non-string indices; the assert statement that was probably inserted by you was the first to actually throw an error; before, integer indices were interpreted .iloc
- style even if there was an integer index... that's the only way I can imagine that the notebook above broke
from anndata.
Well, I think it’s an useful error to throw. We could add a tip on how to resolve it by removing the index…
from anndata.
Yes, it's a useful error, but it shouldn't be thrown in getitem
and it broke the notebook! Instead, an error should be thrown when setting a non-string index; but in that case I accounted for it via a warning, knowing that I would otherwise break things that previously worked.
We shouldn't allow people to have objects in an invalid state and then be surprised by throwing an error later on.
It would be better if here, we output a warning saying that one matches .iloc
-style and not on the elements of the index. This is what happened before, it's OK in many cases and allowed the pancreas notebook referenced above to run through. There might be many such notebooks out there and it would be nice to renable them.
from anndata.
OK! so throwing an error here was a bugfix itself:
I assume that _normalize_index
is just not called correctly when there’s integer indices. The fix is therefore surely more involved than just removing that line or converting it into a warning:
I’m pretty sure that integer indices on anndata with integer names were already broken before that and I just added a nicer error message.
from anndata.
Related Issues (20)
- i cannot read the h5ad object in a conda environment HOT 1
- Policy for format updates HOT 1
- `KeyError` on Flask app using `pyinstaller` with `setuptools_scm` HOT 1
- `dask` `2024.8.0` breaks with `scipy.sparse.{csr,csc}` HOT 1
- backed="r" is leaking memory HOT 1
- ad.experimental.concat_on_disk fills with zeros some obs when concatenating
- Add parameter for more resilient `concat_on_disk` HOT 4
- H5ad converts string/object to categorical when saving and reading HOT 2
- Adding multiple "visits" (clinical data) to a single .obs
- (dev): Automation for cherry-picking release notes to `main` from `0.X.X` branch HOT 2
- (dev): Validate `towncrier` fragments.
- Writing a h5py.Dataset loads the whole thing into memory HOT 1
- Trigger CI Jobs in other Core Repos HOT 2
- `should` should be `must` in `settings`? HOT 1
- 0.11 API HOT 9
- Additional fields in AnnData h5ad and zarr files HOT 3
- (chore): clean up use of `spmatrix` and `sparray`
- (feat): full release automation
- Transition to backed mode fails with .raw specified
- Release regex
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anndata.