-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Fixing EX01 - Added examples #53689
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 2 commits
8e347df
2f9ffe6
d18c825
c271b7a
fa41d00
81c14c7
5febc4e
7f0125a
533fe55
3fdd1a0
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 |
---|---|---|
|
@@ -1531,6 +1531,72 @@ class Timestamp(_Timestamp): | |
) from err | ||
return _dt.ctime() | ||
|
||
def date(self): | ||
""" | ||
Return date object with same year, month and day. | ||
|
||
Examples | ||
-------- | ||
>>> ts = pd.Timestamp('2023-01-01 10:00:00.00') | ||
>>> ts | ||
Timestamp('2023-01-01 10:00:00') | ||
>>> ts.date() | ||
datetime.date(2023, 1, 1) | ||
""" | ||
try: | ||
_dt = datetime(self.year, self.month, self.day, | ||
self.hour, self.minute, self.second, | ||
self.microsecond, self.tzinfo, fold=self.fold) | ||
except ValueError as err: | ||
raise NotImplementedError( | ||
"date not yet supported on Timestamps which " | ||
"are outside the range of Python's standard library. " | ||
"For now, please call the components you need (such as `.year` " | ||
"and `.month`) and construct your string from there." | ||
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're not constructing a string, so we can remove this part of the message |
||
) from err | ||
return _dt.date() | ||
|
||
def dst(self): | ||
""" | ||
Return self.tzinfo.dst(self). | ||
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. How about
|
||
|
||
Examples | ||
-------- | ||
>>> ts = pd.Timestamp('2000-06-01 00:00:00', | ||
... tz='Europe/Brussels').dst() | ||
>>> ts | ||
datetime.timedelta(seconds=3600) | ||
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.
>>> ts = pd.Timestamp('2000-06-01 00:00:00', tz='Europe/Brussels')
>>> ts.dst()
datetime.timedelta(seconds=3600) |
||
""" | ||
_dt = datetime(self.year, self.month, self.day, | ||
self.hour, self.minute, self.second, | ||
self.microsecond, self.tzinfo, fold=self.fold) | ||
return _dt.dst() | ||
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. looks like we're not catching anything here, so can we just return
|
||
|
||
def isocalendar(self): | ||
""" | ||
Return a named tuple containing ISO year, week number, and weekday. | ||
|
||
Examples | ||
-------- | ||
>>> ts = pd.Timestamp('2023-01-01 10:00:00') | ||
>>> ts | ||
Timestamp('2023-01-01 10:00:00') | ||
>>> ts.isocalendar() | ||
datetime.IsoCalendarDate(year=2022, week=52, weekday=7) | ||
""" | ||
try: | ||
_dt = datetime(self.year, self.month, self.day, | ||
self.hour, self.minute, self.second, | ||
self.microsecond, self.tzinfo, fold=self.fold) | ||
except ValueError as err: | ||
raise NotImplementedError( | ||
"isocalendar not yet supported on Timestamps which " | ||
"are outside the range of Python's standard library. " | ||
"For now, please call the components you need (such as `.year` " | ||
"and `.month`) and construct your string from there." | ||
MarcoGorelli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) from err | ||
return _dt.isocalendar() | ||
|
||
# Issue 25016. | ||
@classmethod | ||
def strptime(cls, date_string, format): | ||
|
@@ -2384,6 +2450,14 @@ default 'raise' | |
Return the day of the week represented by the date. | ||
|
||
Monday == 1 ... Sunday == 7. | ||
|
||
Examples | ||
-------- | ||
>>> ts = pd.Timestamp('2023-01-01 10:00:00') | ||
>>> ts | ||
Timestamp('2023-01-01 10:00:00') | ||
>>> ts.isoweekday() | ||
7 | ||
""" | ||
# same as super().isoweekday(), but that breaks because of how | ||
# we have overridden year, see note in create_timestamp_from_ts | ||
|
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.
can we construct a
date
object directly, and then return that? like, where
date
is imported fromdatetime
?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.
Thanks for the corrections. :)
I did all of them locally except this one. I can't find how to import date from datetime without breaking it.
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.
might work to do
import datetime as dt
, then usedt.date