From 8c931ef0c8999550946f6a24794eedf4e93e2c9c Mon Sep 17 00:00:00 2001 From: Nipun Sadvilkar Date: Sat, 10 Mar 2018 19:37:33 +0530 Subject: [PATCH 1/6] DOC: Improved the docstring of pandas.date_range() --- pandas/core/indexes/datetimes.py | 37 +++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index e5e9bba269fd4..caa86d0aaae0e 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -2202,29 +2202,30 @@ def _generate_regular_range(start, end, periods, offset): def date_range(start=None, end=None, periods=None, freq='D', tz=None, normalize=False, name=None, closed=None, **kwargs): """ - Return a fixed frequency DatetimeIndex, with day (calendar) as the default - frequency + Return a fixed frequency DatetimeIndex. + + The default frequency is day (calendar). Parameters ---------- start : string or datetime-like, default None - Left bound for generating dates + Left bound for generating dates. end : string or datetime-like, default None - Right bound for generating dates + Right bound for generating dates. periods : integer, default None - Number of periods to generate + Number of periods to generate. freq : string or DateOffset, default 'D' (calendar daily) - Frequency strings can have multiples, e.g. '5H' + Frequency strings can have multiples, e.g. '5H'. tz : string, default None Time zone name for returning localized DatetimeIndex, for example - Asia/Hong_Kong + Asia/Hong_Kong. normalize : bool, default False - Normalize start/end dates to midnight before generating date range + Normalize start/end dates to midnight before generating date range. name : string, default None - Name of the resulting DatetimeIndex + Name of the resulting DatetimeIndex. closed : string, default None Make the interval closed with respect to the given frequency to - the 'left', 'right', or both sides (None) + the 'left', 'right', or both sides (None). Notes ----- @@ -2237,6 +2238,22 @@ def date_range(start=None, end=None, periods=None, freq='D', tz=None, Returns ------- rng : DatetimeIndex + + See Also + ________ + pandas.period_range : Return a fixed frequency PeriodIndex. + pandas.interval_range : Return a fixed frequency IntervalIndex. + + Examples + -------- + >>> import pandas + >>> pandas.date_range('20181003', periods=2) + DatetimeIndex(['2018-10-03', '2018-10-04'], dtype='datetime64[ns]', + freq='D') + + >>> pandas.date_range(start='20180101', end='20180103') + DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03'], + dtype='datetime64[ns]', freq='D') """ return DatetimeIndex(start=start, end=end, periods=periods, freq=freq, tz=tz, normalize=normalize, name=name, From 1cfb6dbc630c70f1ee7b0a48b869774c94894e67 Mon Sep 17 00:00:00 2001 From: Nipun Sadvilkar Date: Sat, 10 Mar 2018 19:51:57 +0530 Subject: [PATCH 2/6] Change date strings to iso format --- pandas/core/indexes/datetimes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index caa86d0aaae0e..6c646fd35acf0 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -2246,12 +2246,12 @@ def date_range(start=None, end=None, periods=None, freq='D', tz=None, Examples -------- - >>> import pandas - >>> pandas.date_range('20181003', periods=2) + >>> import pandas as pd + >>> pd.date_range('2018-10-03', periods=2) DatetimeIndex(['2018-10-03', '2018-10-04'], dtype='datetime64[ns]', freq='D') - >>> pandas.date_range(start='20180101', end='20180103') + >>> pd.date_range(start='2018-01-01', end='20180103') DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03'], dtype='datetime64[ns]', freq='D') """ From 0d6600e63c782d7ec9f20721e6b47d9b4299574a Mon Sep 17 00:00:00 2001 From: Nipun Sadvilkar Date: Sat, 10 Mar 2018 19:53:59 +0530 Subject: [PATCH 3/6] Removed import pands in Examples docstring --- pandas/core/indexes/datetimes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 6c646fd35acf0..8dd6622d6f7c1 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -2246,7 +2246,6 @@ def date_range(start=None, end=None, periods=None, freq='D', tz=None, Examples -------- - >>> import pandas as pd >>> pd.date_range('2018-10-03', periods=2) DatetimeIndex(['2018-10-03', '2018-10-04'], dtype='datetime64[ns]', freq='D') From 887756b2c5537091d265124cc37e2837f5086c0f Mon Sep 17 00:00:00 2001 From: Nipun Sadvilkar Date: Sun, 11 Mar 2018 00:18:09 +0530 Subject: [PATCH 4/6] Add See Also Docstring --- pandas/core/indexes/datetimes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 8dd6622d6f7c1..3aad651bbccd4 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -2240,9 +2240,9 @@ def date_range(start=None, end=None, periods=None, freq='D', tz=None, rng : DatetimeIndex See Also - ________ - pandas.period_range : Return a fixed frequency PeriodIndex. - pandas.interval_range : Return a fixed frequency IntervalIndex. + -------- + pd.period_range : Return a fixed frequency PeriodIndex. + pd.interval_range : Return a fixed frequency IntervalIndex. Examples -------- From 184a0637bc8699877ff2aef4b1be6fc73065d3bb Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Sat, 10 Mar 2018 14:42:46 -0600 Subject: [PATCH 5/6] Update datetimes.py --- pandas/core/indexes/datetimes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 3aad651bbccd4..b434e885f6e4f 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -2241,8 +2241,8 @@ def date_range(start=None, end=None, periods=None, freq='D', tz=None, See Also -------- - pd.period_range : Return a fixed frequency PeriodIndex. - pd.interval_range : Return a fixed frequency IntervalIndex. + pandas.period_range : Return a fixed frequency PeriodIndex. + pandas.interval_range : Return a fixed frequency IntervalIndex. Examples -------- From fd64e2fadaa00f2479841de1608b6c2e6b08f895 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Sat, 10 Mar 2018 14:45:28 -0600 Subject: [PATCH 6/6] Doctests --- pandas/core/indexes/datetimes.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index b434e885f6e4f..2de95caafdd6c 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -2246,11 +2246,12 @@ def date_range(start=None, end=None, periods=None, freq='D', tz=None, Examples -------- - >>> pd.date_range('2018-10-03', periods=2) + >>> pd.date_range('2018-10-03', periods=2) # doctest: +NORMALIZE_WHITESPACE DatetimeIndex(['2018-10-03', '2018-10-04'], dtype='datetime64[ns]', - freq='D') + freq='D') >>> pd.date_range(start='2018-01-01', end='20180103') + ... # doctest: +NORMALIZE_WHITESPACE DatetimeIndex(['2018-01-01', '2018-01-02', '2018-01-03'], dtype='datetime64[ns]', freq='D') """