ENH: added new cache_dates parameter for read_csv func
State: closed

- [x] closes N/A
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

This change allows the user to use caching when parsing dates, which is provided by `to_datetime` function

Labels:
name: Enhancement
name: Datetime
description: Datetime data dtype
name: Performance
description: Memory or execution speed performance
name: IO CSV
description: read_csv, to_csv

Comments:
Hello @anmyachev! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:





There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2019-05-07 08:30:55 UTC
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25990?src=pr&el=h1) Report
> Merging [#25990](https://codecov.io/gh/pandas-dev/pandas/pull/25990?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/70773d952bf52229d7214707ce6d66cee70607cb?src=pr&el=desc) will **decrease** coverage by `49.95%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/25990/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/25990?src=pr&el=tree)

```diff
@@             Coverage Diff             @@
##           master   #25990       +/-   ##
===========================================
- Coverage   91.86%    41.9%   -49.96%     
===========================================
  Files         175      175               
  Lines       52543    52544        +1     
===========================================
- Hits        48267    22021    -26246     
- Misses       4276    30523    +26247
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `?` | |
| #single | `41.9% <100%> (-0.07%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25990?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/parsers.py](https://codecov.io/gh/pandas-dev/pandas/pull/25990/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhcnNlcnMucHk=) | `48.24% <100%> (-47.55%)` | :arrow_down: |
| [pandas/io/formats/latex.py](https://codecov.io/gh/pandas-dev/pandas/pull/25990/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvbGF0ZXgucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/sas/sas\_constants.py](https://codecov.io/gh/pandas-dev/pandas/pull/25990/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfY29uc3RhbnRzLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/plotting.py](https://codecov.io/gh/pandas-dev/pandas/pull/25990/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvcGxvdHRpbmcucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/25990/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvY29udmVydGVyLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/formats/html.py](https://codecov.io/gh/pandas-dev/pandas/pull/25990/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvaHRtbC5weQ==) | `0% <0%> (-99.36%)` | :arrow_down: |
| [pandas/core/groupby/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/25990/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9jYXRlZ29yaWNhbC5weQ==) | `0% <0%> (-95.46%)` | :arrow_down: |
| [pandas/io/sas/sas7bdat.py](https://codecov.io/gh/pandas-dev/pandas/pull/25990/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXM3YmRhdC5weQ==) | `0% <0%> (-91.16%)` | :arrow_down: |
| [pandas/io/sas/sas\_xport.py](https://codecov.io/gh/pandas-dev/pandas/pull/25990/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfeHBvcnQucHk=) | `0% <0%> (-90.1%)` | :arrow_down: |
| [pandas/core/tools/numeric.py](https://codecov.io/gh/pandas-dev/pandas/pull/25990/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvdG9vbHMvbnVtZXJpYy5weQ==) | `10.44% <0%> (-89.56%)` | :arrow_down: |
| ... and [131 more](https://codecov.io/gh/pandas-dev/pandas/pull/25990/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25990?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25990?src=pr&el=footer). Last update [70773d9...c9b258f](https://codecov.io/gh/pandas-dev/pandas/pull/25990?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25990?src=pr&el=h1) Report
> Merging [#25990](https://codecov.io/gh/pandas-dev/pandas/pull/25990?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/64c1127aaf01b501fcc8dc4d31d00accc712952c?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/25990/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/25990?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #25990      +/-   ##
==========================================
- Coverage   91.99%   91.98%   -0.01%     
==========================================
  Files         175      175              
  Lines       52377    52378       +1     
==========================================
- Hits        48182    48180       -2     
- Misses       4195     4198       +3
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.53% <100%> (ø)` | :arrow_up: |
| #single | `40.77% <100%> (-0.13%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25990?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/parsers.py](https://codecov.io/gh/pandas-dev/pandas/pull/25990/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3BhcnNlcnMucHk=) | `95.84% <100%> (ø)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/25990/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/25990/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.9% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/25990/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `90.7% <0%> (+0.1%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25990?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25990?src=pr&el=footer). Last update [64c1127...687d0c4](https://codecov.io/gh/pandas-dev/pandas/pull/25990?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

while we are doing this may as well flip the flag in ``pd.to_datetime`` as well to ``True``. (it could be a separate PR), but need to run asv's.
@jreback I made sure that changing `to_datetime` signature should be done in a separate request, because, unfortunately, it is not enough to change it alone, I will have to change the signatures of other functions. So   last commit will be removed from this PR.
Note for reviewers: it seems that this PR have the same errors as master branch
We already have so many datetime parameters at this point, but I'm thinking at some point we should condense them into a `dict`.  This would allow for ease of parameterization without bloat.

@jreback : What do you think?
> I'm thinking at some point we should condense them into a `dict`.

Maybe declare a `collections.namedtuple` for those arguments, so they're fix-named?
> Maybe declare a collections.namedtuple for those arguments, so they're fix-named?

@vnlitvin : I'm actually inclined to leave it as `dict` for the time being.  I would like to keep that portion of the API flexible so that the only limits on how people want to parse dates is the signature underlying our datetime parsing.
`asv continuous -f 1.1 origin/master cache_dates_api_change  -a warmup_time=1 -a sample_time=1`

master | our_patch | ratio | test_name
-|-|-|-
1.45±0.01ms|      1.87±0.01ms|     1.29|  io.csv.ReadCSVParseDates.time_baseline
1.74±0.02ms|      2.24±0.02ms|     1.29|  io.csv.ReadCSVParseDates.time_multiple_date
1.41±0.01ms|      1.56±0.02ms|     1.11|  io.csv.ReadCSVDInferDatetimeFormat.time_read_csv(False, 'iso8601')
1.34±0ms|      1.47±0.02ms|     1.10|  io.csv.ReadCSVDInferDatetimeFormat.time_read_csv(False, 'ymd')
47.3±0.3ms|      6.45±0.04ms|     0.14|  io.csv.ReadCSVCachedParseDates.time_read_csv_cached(True)
@gfyoung condensation of parameters into `dict` should be in a separate PR, shouldn't it?
@anmyachev : Absolutely!  Separate PR would be most appropriate.
@gfyoung ok. Anything left to fix in *this* PR?
small comments, otherwise lgtm. Is that an issue for changing this in ``pd.to_datetime`` as well? (the default)
@jreback when changing the flag in `pd.to_datetime` to true, errors occur on some platforms. I do not remember exactly what the problem was there. But in the near future I will create the PR right with this change. That's when I can answer your question.
@anmyachev  this is a troubling comment. https://github.com/pandas-dev/pandas/pull/25990#issuecomment-481546715

can you show me an example? 
@jreback after getting result of CI tests for #26043 I can show you an example.
I think we can continue our discussion there.
@jreback is there anything left to fix before this could be merged?
@jreback 

> @anmyachev this is a troubling comment. [#25990 (comment)](https://github.com/pandas-dev/pandas/pull/25990#issuecomment-481546715)
> 
> can you show me an example?

Does our example (#26097) satisfy you here? I feel that it shouldn't be a blocker for this PR.

P.S. I've rebased on `master` to get rid of merge conflicts (and to have a clean history).
@jreback @gfyoung anything needed from us?
is there an issue for this?
> is there an issue for this?

@jreback no errors detected for this.
> no errors detected for this.

what does this mean?
> > no errors detected for this.
> 
> what does this mean?

I mean: I not found issue for this.
> is there an issue for this?

If you mean Github issue then no, we didn't file one and we didn't fine any.
That's why this PR is used as a reference in `whatsnew`.
can you merge master.
@jreback Done & green
thanks @anmyachev 
Are we OK with this slowdown on the parse dates benchmark? http://pandas.pydata.org/speed/pandas/index.html#io.csv.ReadCSVParseDates.time_multiple_date?commits=f65742cd47d6b364a2cbf150869b282c5aa7daf0