twelvedata / twelvedata-python

Twelve Data Python Client - Financial data API & WebSocket
https://twelvedata.com
MIT License
392 stars 57 forks source link

[Feature Request/Bug] as_pandas() for quote endpoint #53

Closed SimonDamberg closed 2 years ago

SimonDamberg commented 2 years ago

It is not clear from the documentation if as_pandas() is supported for other core endpoints than time_series since the use case is the same, and nothing regarding supported datatypes are mentioned. It would be nice to have quotes supporting as_pandas().

When calling as_pandas() on a QuoteEndpoint object, I get the following error:

Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniforge/base/envs/api/lib/python3.9/site-packages/twelvedata/utils.py", line 147, in convert_collection_to_pandas
    return pandas.DataFrame.from_dict(val, orient="index", dtype="float")
  File "/opt/homebrew/Caskroom/miniforge/base/envs/api/lib/python3.9/site-packages/pandas/core/frame.py", line 1677, in from_dict
    return cls(data, index=index, columns=columns, dtype=dtype)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/api/lib/python3.9/site-packages/pandas/core/frame.py", line 737, in __init__
    mgr = ndarray_to_mgr(
  File "/opt/homebrew/Caskroom/miniforge/base/envs/api/lib/python3.9/site-packages/pandas/core/internals/construction.py", line 340, in ndarray_to_mgr
    values = sanitize_array(
  File "/opt/homebrew/Caskroom/miniforge/base/envs/api/lib/python3.9/site-packages/pandas/core/construction.py", line 567, in sanitize_array
    subarr = _try_cast(data, dtype, copy, raise_cast_failure)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/api/lib/python3.9/site-packages/pandas/core/construction.py", line 781, in _try_cast
    subarr = np.array(arr, dtype=dtype, copy=copy)
ValueError: could not convert string to float: 'AAPL'
sgacode commented 2 years ago

Fixed in release 1.2.8 https://pypi.org/project/twelvedata/1.2.8/