From a09e015dd8cf6369ad385c30aaa50724368982c4 Mon Sep 17 00:00:00 2001 From: Saurav Chakravorty Date: Tue, 5 Feb 2019 23:24:03 +0530 Subject: [PATCH 1/2] updates to Timestamp document --- pandas/_libs/tslibs/timestamps.pyx | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index cad63b4323015..70476a99f3b9e 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -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 @@ -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') @@ -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): @@ -983,30 +992,48 @@ 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 @@ -1014,6 +1041,9 @@ class Timestamp(_Timestamp): @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 @@ -1021,6 +1051,9 @@ class Timestamp(_Timestamp): @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 @@ -1028,6 +1061,9 @@ class Timestamp(_Timestamp): @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 @@ -1035,6 +1071,9 @@ class Timestamp(_Timestamp): @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 @@ -1042,6 +1081,9 @@ class Timestamp(_Timestamp): @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 @@ -1049,6 +1091,9 @@ class Timestamp(_Timestamp): @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', From 2aec9ae5b6b994e0aec76327124b8162a25617ce Mon Sep 17 00:00:00 2001 From: Saurav Chakravorty Date: Tue, 5 Feb 2019 23:28:41 +0530 Subject: [PATCH 2/2] Some more fixes --- pandas/_libs/tslibs/timestamps.pyx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 70476a99f3b9e..25b0b4069cf7c 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -505,7 +505,7 @@ cdef class _Timestamp(datetime): @property def asm8(self): """ - Return numpy datetime64 format in nanoseconds + Return numpy datetime64 format in nanoseconds. """ return np.datetime64(self.value, 'ns') @@ -1032,7 +1032,7 @@ class Timestamp(_Timestamp): @property def is_month_start(self): """ - Return true if date is first day of month. + Return True if date is first day of month. """ if self.freq is None: # fast-path for non-business frequencies @@ -1042,7 +1042,7 @@ class Timestamp(_Timestamp): @property def is_month_end(self): """ - Return true if date is last day of month. + Return True if date is last day of month. """ if self.freq is None: # fast-path for non-business frequencies @@ -1052,7 +1052,7 @@ class Timestamp(_Timestamp): @property def is_quarter_start(self): """ - Return true if date is first day of the quarter. + Return True if date is first day of the quarter. """ if self.freq is None: # fast-path for non-business frequencies @@ -1062,7 +1062,7 @@ class Timestamp(_Timestamp): @property def is_quarter_end(self): """ - Return true if date is last day of the quarter. + Return True if date is last day of the quarter. """ if self.freq is None: # fast-path for non-business frequencies @@ -1072,7 +1072,7 @@ class Timestamp(_Timestamp): @property def is_year_start(self): """ - Return true if date is first day of the year. + Return True if date is first day of the year. """ if self.freq is None: # fast-path for non-business frequencies @@ -1082,7 +1082,7 @@ class Timestamp(_Timestamp): @property def is_year_end(self): """ - Return true if date is last day of the year. + Return True if date is last day of the year. """ if self.freq is None: # fast-path for non-business frequencies @@ -1092,7 +1092,7 @@ class Timestamp(_Timestamp): @property def is_leap_year(self): """ - Return true if year is a leap year. + Return True if year is a leap year. """ return bool(ccalendar.is_leapyear(self.year))