-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
REF: implement Categorical._box_func, make _box_func a method #36206
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
Conversation
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.
small comment, ok if you want to do as a followon as well
pandas/core/arrays/timedeltas.py
Outdated
@property | ||
def _box_func(self): | ||
return lambda x: Timedelta(x, unit="ns") | ||
def _box_func(self, 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.
ideally can you type the returns
annotated+green |
@property | ||
def _box_func(self): | ||
return lambda x: Period._from_ordinal(ordinal=x, freq=self.freq) | ||
def _box_func(self, x) -> Union[Period, NaTType]: |
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.
should alias this kind of type at somepoint, maybe PeriodOrNaT (and the others as well)
Defining
_box_func
onCategorical
is to facilitate more code sharing with datetimelike. Also there are a bunch of places that do something similar but slightly different that I want to standardize withinCategorical
.Changing
_box_func
from a property-lambda to a method on the datetimelike arrays gives a slight perf boost: