From 5468cc02296b51379beddfa60131cbdbf159b18f Mon Sep 17 00:00:00 2001 From: Hyukjin Kwon Date: Wed, 15 May 2019 21:31:22 +0900 Subject: [PATCH] DOC: Test doctests in pandas/core/tools/datetimes.py (#26402) --- ci/code_checks.sh | 4 ++++ pandas/core/tools/datetimes.py | 18 ++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 6d8e03d0896ae..3d1ec637ae202 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -239,6 +239,10 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then pytest -q --doctest-modules pandas/core/groupby/groupby.py -k"-cumcount -describe -pipe" RET=$(($RET + $?)) ; echo $MSG "DONE" + MSG='Doctests datetimes.py' ; echo $MSG + pytest -q --doctest-modules pandas/core/tools/datetimes.py + RET=$(($RET + $?)) ; echo $MSG "DONE" + MSG='Doctests top-level reshaping functions' ; echo $MSG pytest -q --doctest-modules \ pandas/core/reshape/concat.py \ diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index 0b0916026cd30..817d539d4ad6f 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -525,8 +525,8 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False, 'ms', 'us', 'ns']) or plurals of the same >>> df = pd.DataFrame({'year': [2015, 2016], - 'month': [2, 3], - 'day': [4, 5]}) + ... 'month': [2, 3], + ... 'day': [4, 5]}) >>> pd.to_datetime(df) 0 2015-02-04 1 2016-03-05 @@ -548,8 +548,7 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False, Passing infer_datetime_format=True can often-times speedup a parsing if its not an ISO8601 format exactly, but in a regular format. - >>> s = pd.Series(['3/11/2000', '3/12/2000', '3/13/2000']*1000) - + >>> s = pd.Series(['3/11/2000', '3/12/2000', '3/13/2000'] * 1000) >>> s.head() 0 3/11/2000 1 3/12/2000 @@ -558,10 +557,10 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False, 4 3/12/2000 dtype: object - >>> %timeit pd.to_datetime(s,infer_datetime_format=True) + >>> %timeit pd.to_datetime(s,infer_datetime_format=True) # doctest: +SKIP 100 loops, best of 3: 10.4 ms per loop - >>> %timeit pd.to_datetime(s,infer_datetime_format=False) + >>> %timeit pd.to_datetime(s,infer_datetime_format=False) # doctest: +SKIP 1 loop, best of 3: 471 ms per loop Using a unix epoch time @@ -577,10 +576,9 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False, Using a non-unix epoch origin >>> pd.to_datetime([1, 2, 3], unit='D', - origin=pd.Timestamp('1960-01-01')) - 0 1960-01-02 - 1 1960-01-03 - 2 1960-01-04 + ... origin=pd.Timestamp('1960-01-01')) + DatetimeIndex(['1960-01-02', '1960-01-03', '1960-01-04'], \ +dtype='datetime64[ns]', freq=None) """ if arg is None: return None