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

DOC: Updates to Timestamp document #25163

Merged
merged 2 commits into from
Feb 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@ cdef class _Timestamp(datetime):

@property
def asm8(self):
"""
Return numpy datetime64 format in nanoseconds.
"""
return np.datetime64(self.value, 'ns')

@property
Expand Down Expand Up @@ -570,15 +573,18 @@ class Timestamp(_Timestamp):
Using the primary calling convention:

This converts a datetime-like string

>>> pd.Timestamp('2017-01-01T12')
Timestamp('2017-01-01 12:00:00')

This converts a float representing a Unix epoch in units of seconds

>>> pd.Timestamp(1513393355.5, unit='s')
Timestamp('2017-12-16 03:02:35.500000')

This converts an int representing a Unix-epoch in units of seconds
and for a particular timezone

>>> pd.Timestamp(1513393355, unit='s', tz='US/Pacific')
Timestamp('2017-12-15 19:02:35-0800', tz='US/Pacific')

Expand Down Expand Up @@ -934,6 +940,9 @@ class Timestamp(_Timestamp):

@property
def dayofweek(self):
"""
Return day of whe week.
"""
return self.weekday()

def day_name(self, locale=None):
Expand Down Expand Up @@ -983,72 +992,108 @@ class Timestamp(_Timestamp):

@property
def dayofyear(self):
"""
Return the day of the year.
"""
return ccalendar.get_day_of_year(self.year, self.month, self.day)

@property
def week(self):
"""
Return the week number of the year.
"""
return ccalendar.get_week_of_year(self.year, self.month, self.day)

weekofyear = week

@property
def quarter(self):
"""
Return the quarter of the year.
"""
return ((self.month - 1) // 3) + 1

@property
def days_in_month(self):
"""
Return the number of days in the month.
"""
return ccalendar.get_days_in_month(self.year, self.month)

daysinmonth = days_in_month

@property
def freqstr(self):
"""
Return the total number of days in the month.
"""
return getattr(self.freq, 'freqstr', self.freq)

@property
def is_month_start(self):
"""
Return True if date is first day of month.
"""
if self.freq is None:
# fast-path for non-business frequencies
return self.day == 1
return self._get_start_end_field('is_month_start')

@property
def is_month_end(self):
"""
Return True if date is last day of month.
"""
if self.freq is None:
# fast-path for non-business frequencies
return self.day == self.days_in_month
return self._get_start_end_field('is_month_end')

@property
def is_quarter_start(self):
"""
Return True if date is first day of the quarter.
"""
if self.freq is None:
# fast-path for non-business frequencies
return self.day == 1 and self.month % 3 == 1
return self._get_start_end_field('is_quarter_start')

@property
def is_quarter_end(self):
"""
Return True if date is last day of the quarter.
"""
if self.freq is None:
# fast-path for non-business frequencies
return (self.month % 3) == 0 and self.day == self.days_in_month
return self._get_start_end_field('is_quarter_end')

@property
def is_year_start(self):
"""
Return True if date is first day of the year.
"""
if self.freq is None:
# fast-path for non-business frequencies
return self.day == self.month == 1
return self._get_start_end_field('is_year_start')

@property
def is_year_end(self):
"""
Return True if date is last day of the year.
"""
if self.freq is None:
# fast-path for non-business frequencies
return self.month == 12 and self.day == 31
return self._get_start_end_field('is_year_end')

@property
def is_leap_year(self):
"""
Return True if year is a leap year.
"""
return bool(ccalendar.is_leapyear(self.year))

def tz_localize(self, tz, ambiguous='raise', nonexistent='raise',
Expand Down