Skip to content

Commit 2ccd74d

Browse files
Merge pull request #6078 from danbirken/infer-dt-doc-fix
DOC/BUG: Fix documentation for `infer_datetime_format` #6073
2 parents 8a02e68 + 987741c commit 2ccd74d

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

doc/source/io.rst

+16-17
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,6 @@ The simplest case is to just pass in ``parse_dates=True``:
387387
# These are python datetime objects
388388
df.index
389389
390-
.. ipython:: python
391-
:suppress:
392-
393-
os.remove('foo.csv')
394-
395390
It is often the case that we may want to store date and time data separately,
396391
or store various date fields separately. the ``parse_dates`` keyword can be
397392
used to specify a combination of columns to parse the dates and/or times from.
@@ -503,36 +498,40 @@ a single date rather than the entire array.
503498

504499
Inferring Datetime Format
505500
~~~~~~~~~~~~~~~~~~~~~~~~~
506-
If you have `parse_dates` enabled for some or all of your columns, and your
501+
If you have ``parse_dates`` enabled for some or all of your columns, and your
507502
datetime strings are all formatted the same way, you may get a large speed
508-
up by setting `infer_datetime_format=True`. If set, pandas will attempt
503+
up by setting ``infer_datetime_format=True``. If set, pandas will attempt
509504
to guess the format of your datetime strings, and then use a faster means
510505
of parsing the strings. 5-10x parsing speeds have been observed. Pandas
511506
will fallback to the usual parsing if either the format cannot be guessed
512507
or the format that was guessed cannot properly parse the entire column
513-
of strings. So in general, `infer_datetime_format` should not have any
508+
of strings. So in general, ``infer_datetime_format`` should not have any
514509
negative consequences if enabled.
515510

516511
Here are some examples of datetime strings that can be guessed (All
517512
representing December 30th, 2011 at 00:00:00)
518513

519-
"20111230"
520-
"2011/12/30"
521-
"20111230 00:00:00"
522-
"12/30/2011 00:00:00"
523-
"30/Dec/2011 00:00:00"
524-
"30/December/2011 00:00:00"
514+
- "20111230"
515+
- "2011/12/30"
516+
- "20111230 00:00:00"
517+
- "12/30/2011 00:00:00"
518+
- "30/Dec/2011 00:00:00"
519+
- "30/December/2011 00:00:00"
525520

526-
`infer_datetime_format` is sensitive to `dayfirst`. With `dayfirst=True`, it
527-
will guess "01/12/2011" to be December 1st. With `dayfirst=False` (default)
528-
it will guess "01/12/2011" to be January 12th.
521+
``infer_datetime_format`` is sensitive to ``dayfirst``. With
522+
``dayfirst=True``, it will guess "01/12/2011" to be December 1st. With
523+
``dayfirst=False`` (default) it will guess "01/12/2011" to be January 12th.
529524

530525
.. ipython:: python
531526
532527
# Try to infer the format for the index column
533528
df = pd.read_csv('foo.csv', index_col=0, parse_dates=True,
534529
infer_datetime_format=True)
535530
531+
.. ipython:: python
532+
:suppress:
533+
534+
os.remove('foo.csv')
536535
537536
International Date Formats
538537
~~~~~~~~~~~~~~~~~~~~~~~~~~

doc/source/v0.13.1.txt

+7-7
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,19 @@ Enhancements
148148
result
149149
result.loc[:,:,'ItemA']
150150

151-
- Added optional `infer_datetime_format` to `read_csv`, `Series.from_csv` and
152-
`DataFrame.read_csv` (:issue:`5490`)
151+
- Added optional ``infer_datetime_format`` to ``read_csv``, ``Series.from_csv``
152+
and ``DataFrame.read_csv`` (:issue:`5490`)
153153

154-
If `parse_dates` is enabled and this flag is set, pandas will attempt to
154+
If ``parse_dates`` is enabled and this flag is set, pandas will attempt to
155155
infer the format of the datetime strings in the columns, and if it can
156156
be inferred, switch to a faster method of parsing them. In some cases
157157
this can increase the parsing speed by ~5-10x.
158158

159-
.. ipython:: python
159+
.. code-block:: python
160160

161-
# Try to infer the format for the index column
162-
df = pd.read_csv('foo.csv', index_col=0, parse_dates=True,
163-
infer_datetime_format=True)
161+
# Try to infer the format for the index column
162+
df = pd.read_csv('foo.csv', index_col=0, parse_dates=True,
163+
infer_datetime_format=True)
164164

165165
Experimental
166166
~~~~~~~~~~~~

0 commit comments

Comments
 (0)