Skip to content

ValueError when I try to get data from Alpha Vantage #741

Open
@arzieg

Description

@arzieg

Hello,
I have tried the example to get data from alpha vantage (https://pandas-datareader.readthedocs.io/en/latest/remote_data.html#historical-time-series-data) and I got a ValueError:

Traceback (most recent call last):
File "adllib.py", line 40, in
api_key=os.getenv('ALPHAVANTAGE_API_KEY'))
File "/home/arne/dev/python/stock/venv/lib/python3.5/site-packages/pandas/util/_decorators.py", line 188, in wrapper
return func(*args, **kwargs)
File "/home/arne/dev/python/stock/venv/lib/python3.5/site-packages/pandas_datareader/data.py", line 579, in DataReader
api_key=api_key,
File "/home/arne/dev/python/stock/venv/lib/python3.5/site-packages/pandas_datareader/base.py", line 100, in read
return self._read_one_data(self.url, self.params)
File "/home/arne/dev/python/stock/venv/lib/python3.5/site-packages/pandas_datareader/base.py", line 112, in _read_one_data
return self._read_lines(out)
File "/home/arne/dev/python/stock/venv/lib/python3.5/site-packages/pandas_datareader/av/time_series.py", line 112, in _read_lines
raise ValueError("Please input a valid date range")
ValueError: Please input a valid date range

I have also tried the test procedure with pytest:

pytest -v test_av_time_series.py::TestAVTimeSeries::test_av_daily
============================================================================================================ test session starts ============================================================================================================
platform linux -- Python 3.5.2, pytest-5.3.2, py-1.8.1, pluggy-0.13.1 -- /home/arne/dev/python/stock/venv/bin/python
cachedir: .pytest_cache
rootdir: /home/arne/dev/python/stock
collected 1 item

test_av_time_series.py::TestAVTimeSeries::test_av_daily FAILED [100%]

================================================================================================================= FAILURES ==================================================================================================================
______________________________________________________________________________________________________ TestAVTimeSeries.test_av_daily _______________________________________________________________________________________________________

self = <pandas_datareader.tests.av.test_av_time_series.TestAVTimeSeries object at 0x7f85079867f0>

def test_av_daily(self):
    df = web.DataReader(
        "AAPL",
        "av-daily",
        start=self.start,
        end=self.end,
        retry_count=6,
      pause=20.5,
    )

test_av_time_series.py:63:


../../../pandas/util/_decorators.py:188: in wrapper
return func(*args, **kwargs)
../../data.py:579: in DataReader
api_key=api_key,
../../base.py:100: in read
return self._read_one_data(self.url, self.params)
../../base.py:112: in _read_one_data
return self._read_lines(out)


self = <pandas_datareader.av.time_series.AVTimeSeriesReader object at 0x7f8507984eb8>
out = {'Meta Data': {'1. Information': 'Daily Prices (open, high, low, close) and Volumes', '2. Symbol': 'AAPL', '3. Last Re..., '1999-12-30': {'1. open': '102.1900', '2. high': '104.1200', '3. low': '99.6200', '4. close': '100.3100', ...}, ...}}

def _read_lines(self, out):
    data = super(AVTimeSeriesReader, self)._read_lines(out)
    # reverse since alphavantage returns descending by date
    data = data[::-1]
    start_str = self.start.strftime("%Y-%m-%d")
    end_str = self.end.strftime("%Y-%m-%d")
    data = data.loc[start_str:end_str]
    if data.empty:
      raise ValueError("Please input a valid date range")

E ValueError: Please input a valid date range

../../av/time_series.py:112: ValueError

Best regards

arne

Activity

aGrimRepoMan

aGrimRepoMan commented on Jan 15, 2020

@aGrimRepoMan
jzaiwei

jzaiwei commented on May 2, 2020

@jzaiwei

I have the same problem, how to fix it ? The 662 issues is disappeared

added a commit that references this issue on Mar 1, 2021
linked a pull request that will close this issue on Mar 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @jzaiwei@arzieg@aGrimRepoMan

      Issue actions

        ValueError when I try to get data from Alpha Vantage · Issue #741 · pydata/pandas-datareader