Skip to content

Commit 98c1d2d

Browse files
Merge pull request #129 from davidastephens/doc_cache
DOC: Add cache documentation
2 parents 416c42f + 283f2bd commit 98c1d2d

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

docs/source/cache.rst

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.. _cache:
2+
3+
.. currentmodule:: pandas-datareader
4+
5+
.. ipython:: python
6+
:suppress:
7+
8+
import numpy as np
9+
from pandas import *
10+
import pandas as pd
11+
import requests_cache
12+
randn = np.random.randn
13+
np.set_printoptions(precision=4, suppress=True)
14+
options.display.max_rows = 15
15+
16+
***************
17+
Caching queries
18+
***************
19+
20+
Making the same request repeatedly can use a lot of bandwidth, slow down your
21+
code and may result in your IP being banned.
22+
23+
``pandas-datareader`` allows you to cache queries using ``requests_cache`` by
24+
passing a ``requests_cache.Session`` to ``DataReader`` or ``Options`` using the
25+
``session`` parameter.
26+
27+
Below is an example with Yahoo! Finance. The session parameter is implemented for all datareaders.
28+
29+
.. ipython:: python
30+
31+
import pandas_datareader.data as web
32+
import datetime
33+
import requests_cache
34+
expire_after = datetime.timedelta(days=3)
35+
session = requests_cache.CachedSession(cache_name='cache', backend='sqlite', expire_after=expire_after)
36+
start = datetime.datetime(2010, 1, 1)
37+
end = datetime.datetime(2013, 1, 27)
38+
f = web.DataReader("F", 'yahoo', start, end, session=session)
39+
f.ix['2010-01-04']
40+
41+
A `SQLite <https://www.sqlite.org/>`_ file named ``cache.sqlite`` will be created in the working
42+
directory, storing the request until the expiry date.
43+
44+
For additional information on using requests-cache, see the
45+
`documentation <http://requests-cache.readthedocs.org/>`_.

docs/source/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Contents:
1616

1717
whatsnew.rst
1818
remote_data.rst
19-
19+
cache.rst
2020

2121

2222
Indices and tables

docs/source/whatsnew/v0.2.1.txt

+2-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
v0.2.1 (XXX)
44
----------------------------
55

6-
This is a minor release from 0.2.0 and includes new features and a number of bug fixes.
6+
This is a minor release from 0.2.0 and includes new features and bug fixes.
77

88

99
Highlights include:
@@ -20,16 +20,11 @@ New features
2020

2121
- ``DataReader`` now supports Eurostat data sources, see :ref:`here<remote_data.eurostat>` (:issue:`101`).
2222
- ``Options`` downloading is approximately 4x faster as a result of a rewrite of the parsing function. (:issue: `122`)
23+
- ``DataReader`` and ``Options`` now support caching, see :ref:`here<cache>` (:issue:`110`),(:issue:`116`),(:issue:`121`), (:issue:`122`).
2324

2425
.. _whatsnew_021.api_breaking:
2526

2627
Backwards incompatible API changes
2728
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2829
- ``Options`` columns ``PctChg`` and ``IV`` (Implied Volatility) are now type float
2930
rather than string. (:issue: `122`)
30-
31-
.. _whatsnew_021.bug_fixes:
32-
33-
Bug Fixes
34-
~~~~~~~~~
35-

0 commit comments

Comments
 (0)