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
(feat): add setting to retain categories #1340
Conversation
ilan-gold
commented
Jan 26, 2024
- Closes Option to retain categories in columns when subsetting anndata object. #890
- Tests added
- Release note added (or unnecessary)
for more information, see https://pre-commit.ci
…categories_setting
anndata/_config.py
Outdated
allowed_values: Sequence[str] | None = None, | ||
cast: Callable[[Any], T] = lambda x: x, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, maybe this can be simplified to
allowed_values: Sequence[str] | None = None, | |
cast: Callable[[Any], T] = lambda x: x, | |
cast: Callable[[Any], T] | type[Enum] = lambda x: x, |
- if it’s a callable, just call it and let the error go through if it fails
- if it’s an enum type, use
cast[val]
to get it by name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I typed cast[val]
for a reason.
class Test(Enum):
a = 1
b = 2
assert Test["a"] is Test.a
assert Test(1) is Test.a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to add second change, apologies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1340 (comment)