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

(feat): add setting to retain categories #1340

Merged
merged 83 commits into from Feb 8, 2024
Merged

(feat): add setting to retain categories #1340

merged 83 commits into from Feb 8, 2024

Conversation

ilan-gold
Copy link
Contributor

Base automatically changed from ig/settings to main January 30, 2024 11:00
@ilan-gold ilan-gold marked this pull request as ready for review January 30, 2024 11:03
Comment on lines 296 to 297
allowed_values: Sequence[str] | None = None,
cast: Callable[[Any], T] = lambda x: x,
Copy link
Member

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

Suggested change
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

Copy link
Member

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

Copy link
Contributor Author

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.

anndata/_config.py Outdated Show resolved Hide resolved
anndata/_config.py Outdated Show resolved Hide resolved
Copy link
Member

@flying-sheep flying-sheep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilan-gold ilan-gold merged commit f10bbde into main Feb 8, 2024
13 checks passed
@ilan-gold ilan-gold deleted the categories_setting branch February 8, 2024 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to retain categories in columns when subsetting anndata object.
3 participants