-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: provide compat for Timestamp now/today/utcnow class methods (GH5339) #5342
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 all commits
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 |
---|---|---|
|
@@ -140,6 +140,22 @@ class Timestamp(_Timestamp): | |
note: by definition there cannot be any tz info on the ordinal itself """ | ||
return cls(datetime.fromordinal(ordinal),offset=offset,tz=tz) | ||
|
||
@classmethod | ||
def now(cls, tz=None): | ||
""" compat now with datetime """ | ||
if isinstance(tz, basestring): | ||
tz = pytz.timezone(tz) | ||
return cls(datetime.now(tz)) | ||
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. @cpcloud so is this the right option here? Or should it just be " 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. it's fine the way it is and that would depend on 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. this is what 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. yep ... looks good to me |
||
|
||
@classmethod | ||
def today(cls): | ||
""" compat today with datetime """ | ||
return cls(datetime.today()) | ||
|
||
@classmethod | ||
def utcnow(cls): | ||
return cls.now('UTC') | ||
|
||
def __new__(cls, object ts_input, object offset=None, tz=None, unit=None): | ||
cdef _TSObject ts | ||
cdef _Timestamp ts_base | ||
|
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.
neat, didn't know you could use decorators in Cython at all...
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.
yep u can use them to tell cython not to check array bounds too, for example.
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.
ah, right the 'fake' cython decorators.
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.
they are real. like u said, cython implements decorators. i think cython is a superset of python so all of python is implemented, with the exception of assignment in the body of a class.