Skip to content

Commit

Permalink
Merge pull request #145 from PatrickAlphaVantage/develop
Browse files Browse the repository at this point in the history
fixing dtype float error on global quote handling
  • Loading branch information
PatrickAlphaC authored Sep 12, 2019
2 parents fef42e2 + 1a2b1ac commit 2bcae29
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions alpha_vantage/alphavantage.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,21 @@ def _format_wrapper(self, *args, **kwargs):
data_pandas = pandas.DataFrame(data_array, columns=[
k for k, _ in data[0].items()])
else:
data_pandas = pandas.DataFrame.from_dict(data,
orient='index',
dtype=float)
try:
data_pandas = pandas.DataFrame.from_dict(data,
orient='index',
dtype='float')
# This is for Global quotes or any other new Alpha Vantage
# data that is added.
# It will have to be updated so that we can get exactly
# The dataframes we want moving forward
except ValueError:
data = {data_key: data}
data_pandas = pandas.DataFrame.from_dict(data,
orient='index',
dtype='object')
return data_pandas, meta_data

if 'integer' in self.indexing_type:
# Set Date as an actual column so a new numerical index
# will be created, but only when specified by the user.
Expand All @@ -197,7 +209,8 @@ def _format_wrapper(self, *args, **kwargs):
else:
data_pandas.index.name = 'date'
# convert to pandas._libs.tslibs.timestamps.Timestamp
data_pandas.index = pandas.to_datetime(data_pandas.index)
data_pandas.index = pandas.to_datetime(
data_pandas.index)
return data_pandas, meta_data
elif 'csv' in self.output_format.lower():
return call_response, None
Expand Down

0 comments on commit 2bcae29

Please sign in to comment.