From 054ac692ad2cb617c115295c40161ddbe80859bf Mon Sep 17 00:00:00 2001 From: Rok Date: Sat, 10 Mar 2018 15:07:23 +0100 Subject: [PATCH 1/3] adding docstring to pandas.Series.dt.is_leap_year --- pandas/core/indexes/datetimes.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index e5e9bba269fd4..fb891cc8a475a 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1751,7 +1751,32 @@ def freq(self, value): is_leap_year = _field_accessor( 'is_leap_year', 'is_leap_year', - "Logical indicating if the date belongs to a leap year") + """ + Return a boolean indicating if the date belongs to a leap year. + + A leap year is a year, occurring every four years, which has 366 days + (instead of 365) including 29th of February as an intercalary day. + + Returns + ------- + is_leap_year : Series of boolean + + Examples + -------- + >>> import pandas as pd + >>> dates = pd.date_range("2012-01-01", "2015-01-01", freq="Y") + >>> dates_series = pd.Series(dates) + >>> dates_series + 0 2012-12-31 + 1 2013-12-31 + 2 2014-12-31 + dtype: datetime64[ns] + >>> dates_series.dt.is_leap_year + 0 True + 1 False + 2 False + dtype: bool + """) @property def time(self): From 605fd20eff4e00476203cc727fcb538a351f4512 Mon Sep 17 00:00:00 2001 From: Rok Date: Sun, 11 Mar 2018 00:28:13 +0100 Subject: [PATCH 2/3] correcting docstring --- pandas/core/indexes/datetimes.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 6bccd8a2ebed3..213c3dce223c8 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1756,16 +1756,18 @@ def freq(self, value): """ Return a boolean indicating if the date belongs to a leap year. - A leap year is a year, occurring every four years, which has 366 days - (instead of 365) including 29th of February as an intercalary day. + A leap year is a year, which has 366 days (instead of 365) including + 29th of February as an intercalary day. + Leap years are years which are multiples of four with the exception + of years divisible by 100 but not by 400. Returns ------- - is_leap_year : Series of boolean + Series + Booleans indicating if dates belong to a leap year. Examples -------- - >>> import pandas as pd >>> dates = pd.date_range("2012-01-01", "2015-01-01", freq="Y") >>> dates_series = pd.Series(dates) >>> dates_series From 132c33557d3eecf277b77077e52d2483dc5c6c2e Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Sat, 17 Mar 2018 12:29:49 +0100 Subject: [PATCH 3/3] make generic for index/series --- pandas/core/indexes/datetimes.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 3a0e45e11aa93..ac7db1dbc4b8f 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -1946,7 +1946,7 @@ def freq(self, value): 'is_leap_year', 'is_leap_year', """ - Return a boolean indicating if the date belongs to a leap year. + Boolean indicator if the date belongs to a leap year. A leap year is a year, which has 366 days (instead of 365) including 29th of February as an intercalary day. @@ -1955,13 +1955,22 @@ def freq(self, value): Returns ------- - Series + Series or ndarray Booleans indicating if dates belong to a leap year. Examples -------- - >>> dates = pd.date_range("2012-01-01", "2015-01-01", freq="Y") - >>> dates_series = pd.Series(dates) + This method is available on Series with datetime values under + the ``.dt`` accessor, and directly on DatetimeIndex. + + >>> idx = pd.date_range("2012-01-01", "2015-01-01", freq="Y") + >>> idx + DatetimeIndex(['2012-12-31', '2013-12-31', '2014-12-31'], + dtype='datetime64[ns]', freq='A-DEC') + >>> idx.is_leap_year + array([ True, False, False], dtype=bool) + + >>> dates = pd.Series(idx) >>> dates_series 0 2012-12-31 1 2013-12-31