Skip to content

Commit 5468cc0

Browse files
HyukjinKwonjreback
authored andcommitted
DOC: Test doctests in pandas/core/tools/datetimes.py (#26402)
1 parent 3ee85e1 commit 5468cc0

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

ci/code_checks.sh

+4
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
239239
pytest -q --doctest-modules pandas/core/groupby/groupby.py -k"-cumcount -describe -pipe"
240240
RET=$(($RET + $?)) ; echo $MSG "DONE"
241241

242+
MSG='Doctests datetimes.py' ; echo $MSG
243+
pytest -q --doctest-modules pandas/core/tools/datetimes.py
244+
RET=$(($RET + $?)) ; echo $MSG "DONE"
245+
242246
MSG='Doctests top-level reshaping functions' ; echo $MSG
243247
pytest -q --doctest-modules \
244248
pandas/core/reshape/concat.py \

pandas/core/tools/datetimes.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,8 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
525525
'ms', 'us', 'ns']) or plurals of the same
526526
527527
>>> df = pd.DataFrame({'year': [2015, 2016],
528-
'month': [2, 3],
529-
'day': [4, 5]})
528+
... 'month': [2, 3],
529+
... 'day': [4, 5]})
530530
>>> pd.to_datetime(df)
531531
0 2015-02-04
532532
1 2016-03-05
@@ -548,8 +548,7 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
548548
Passing infer_datetime_format=True can often-times speedup a parsing
549549
if its not an ISO8601 format exactly, but in a regular format.
550550
551-
>>> s = pd.Series(['3/11/2000', '3/12/2000', '3/13/2000']*1000)
552-
551+
>>> s = pd.Series(['3/11/2000', '3/12/2000', '3/13/2000'] * 1000)
553552
>>> s.head()
554553
0 3/11/2000
555554
1 3/12/2000
@@ -558,10 +557,10 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
558557
4 3/12/2000
559558
dtype: object
560559
561-
>>> %timeit pd.to_datetime(s,infer_datetime_format=True)
560+
>>> %timeit pd.to_datetime(s,infer_datetime_format=True) # doctest: +SKIP
562561
100 loops, best of 3: 10.4 ms per loop
563562
564-
>>> %timeit pd.to_datetime(s,infer_datetime_format=False)
563+
>>> %timeit pd.to_datetime(s,infer_datetime_format=False) # doctest: +SKIP
565564
1 loop, best of 3: 471 ms per loop
566565
567566
Using a unix epoch time
@@ -577,10 +576,9 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
577576
Using a non-unix epoch origin
578577
579578
>>> pd.to_datetime([1, 2, 3], unit='D',
580-
origin=pd.Timestamp('1960-01-01'))
581-
0 1960-01-02
582-
1 1960-01-03
583-
2 1960-01-04
579+
... origin=pd.Timestamp('1960-01-01'))
580+
DatetimeIndex(['1960-01-02', '1960-01-03', '1960-01-04'], \
581+
dtype='datetime64[ns]', freq=None)
584582
"""
585583
if arg is None:
586584
return None

0 commit comments

Comments
 (0)