-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Implement _make_accessor classmethod for PandasDelegate #17166
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,6 +165,12 @@ def __setattr__(self, key, value): | |
class PandasDelegate(PandasObject): | ||
""" an abstract base class for delegating methods/properties """ | ||
|
||
@classmethod | ||
def _make_accessor(cls, data): | ||
raise NotImplementedError("_make_accessor should be implemented" | ||
"by subclass. It should return an instance" | ||
"of `cls`.") | ||
|
||
def _delegate_property_get(self, name, *args, **kwargs): | ||
raise TypeError("You cannot access the " | ||
"property {name}".format(name=name)) | ||
|
@@ -231,8 +237,11 @@ class AccessorProperty(object): | |
"""Descriptor for implementing accessor properties like Series.str | ||
""" | ||
|
||
def __init__(self, accessor_cls, construct_accessor): | ||
def __init__(self, accessor_cls, construct_accessor=None): | ||
self.accessor_cls = accessor_cls | ||
if construct_accessor is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
# We are assuming that `_make_accessor` classmethod exists. | ||
construct_accessor = accessor_cls._make_accessor | ||
self.construct_accessor = construct_accessor | ||
self.__doc__ = accessor_cls.__doc__ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,3 +243,11 @@ class CombinedDatetimelikeProperties(DatetimeProperties, TimedeltaProperties): | |
# the Series.dt class property. For Series objects, .dt will always be one | ||
# of the more specific classes above. | ||
__doc__ = DatetimeProperties.__doc__ | ||
|
||
@classmethod | ||
def _make_accessor(cls, data): | ||
try: | ||
return maybe_to_datetimelike(data) | ||
except Exception: | ||
raise AttributeError("Can only use .dt accessor with datetimelike " | ||
"values") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: can we re-organize so that we don't have a lone word on this line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. I'll take care of this and anything else that piles up this evening. To the extent that we can exercise self-control, I'm fervently hoping to keep the nitpicking back in #17042. |
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.
Use instead: "_make_accessor should be implemented by subclass and return an instance of
cls
."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.
we have AbstracMethodError for this