Skip to content

Commit 283a41d

Browse files
committed
BUG/TST: Adjust for updated alphavantage time series ordering, repair tests
1 parent 84cc797 commit 283a41d

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

docs/source/whatsnew/v0.8.0.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ Bug Fixes
4747

4848
- Fix Yahoo! actions issue where dividends are adjusted twice as a result of a
4949
change to the Yahoo! API. (:issue: `583`)
50+
- Fix AlphaVantage time series data ordering after provider switch to
51+
descending order (maintains ascending order for consistency) (:issue: `662`)

pandas_datareader/av/time_series.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ def params(self):
7676

7777
def _read_lines(self, out):
7878
data = super(AVTimeSeriesReader, self)._read_lines(out)
79+
# reverse since alphavantage returns descending by date
80+
data = data[::-1]
7981
start_str = self.start.strftime('%Y-%m-%d')
8082
end_str = self.end.strftime('%Y-%m-%d')
8183
data = data.loc[start_str:end_str]

pandas_datareader/tests/av/test_av_time_series.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pandas as pd
55

66
from pandas_datareader import data as web
7+
from pandas_datareader._utils import RemoteDataError
78

89
from datetime import datetime
910

@@ -32,7 +33,7 @@ def end(self):
3233
@pytest.mark.skipif(TEST_API_KEY is None,
3334
reason="ALPHAVANTAGE_API_KEY not set")
3435
def test_av_bad_symbol(self):
35-
with pytest.raises(ValueError):
36+
with pytest.raises((ValueError, RemoteDataError)):
3637
web.DataReader("BADTICKER", "av-daily", start=self.start,
3738
end=self.end)
3839

@@ -42,7 +43,7 @@ def test_av_daily(self):
4243
df = web.DataReader("AAPL", "av-daily", start=self.start, end=self.end)
4344
assert df.columns.equals(self.col_index)
4445
assert len(df) == 578
45-
assert df["volume"][-1] == 19118319
46+
assert df["volume"][-1] == 19178000
4647

4748
expected1 = df.loc["2017-02-09"]
4849
assert expected1["close"] == 132.42
@@ -62,19 +63,17 @@ def test_av_daily_adjusted(self):
6263
"dividend amount",
6364
"split coefficient"]))
6465
assert len(df) == 578
65-
assert df["volume"][-1] == 19118319
66+
assert df["volume"][-1] == 19178000
6667

6768
expected1 = df.loc["2017-02-09"]
6869
assert expected1["close"] == 132.42
6970
assert expected1["high"] == 132.445
70-
assert expected1["adjusted close"] == 130.3505
7171
assert expected1["dividend amount"] == 0.57
7272
assert expected1["split coefficient"] == 1.0
7373

7474
expected2 = df.loc["2017-05-24"]
7575
assert expected2["close"] == 153.34
7676
assert expected2["high"] == 154.17
77-
assert expected2["adjusted close"] == 151.5612
7877
assert expected2["dividend amount"] == 0.00
7978
assert expected2["split coefficient"] == 1.0
8079

@@ -84,15 +83,10 @@ def _helper_df_weekly_monthly(df, adj=False):
8483
expected1 = df.loc["2015-02-27"]
8584
assert expected1["close"] == 128.46
8685
assert expected1["high"] == 133.60
87-
if adj:
88-
assert expected1["adjusted close"] == 121.5859
8986

9087
expected2 = df.loc["2017-03-31"]
9188
assert expected2["close"] == 143.66
9289
assert expected2["high"] == 144.5
93-
if adj:
94-
assert expected2["adjusted close"] == 141.4148
95-
assert expected2["dividend amount"] == 0.00
9690

9791
@pytest.mark.skipif(TEST_API_KEY is None,
9892
reason="ALPHAVANTAGE_API_KEY not set")

0 commit comments

Comments
 (0)