ta icon indicating copy to clipboard operation
ta copied to clipboard

Pandas IndexError: single positional indexer is out-of-bounds

Open Jeevan-J opened this issue 3 years ago • 4 comments

When running the latest version's add_volume_ta, we are getting IndexError may be due to deprecated use of .iloc with only single index.

Attaching the complete error here


IndexError Traceback (most recent call last) in 1 for file in listOfFiles: ----> 2 add_indicators(file)

in add_indicators(file) 12 df = dropna(df) 13 ---> 14 df = ta.add_volume_ta(df, "high", "low", "close", "volume", fillna=True) 15 # Add all ta features 16 # df = add_all_ta_features(df, open="open", high="high", low="low", close="close", volume="volume")

c:\users\jeeva\documents\py_projects\general\lib\site-packages\ta\wrapper.py in add_volume_ta(df, high, low, close, volume, fillna, colprefix) 130 # Negative Volume Index 131 df[f"{colprefix}volume_nvi"] = NegativeVolumeIndexIndicator( --> 132 close=df[close], volume=df[volume], fillna=fillna 133 ).negative_volume_index() 134

c:\users\jeeva\documents\py_projects\general\lib\site-packages\ta\volume.py in init(self, close, volume, fillna) 306 self._volume = volume 307 self._fillna = fillna --> 308 self._run() 309 310 def _run(self):

c:\users\jeeva\documents\py_projects\general\lib\site-packages\ta\volume.py in _run(self) 314 data=np.nan, index=self._close.index, dtype="float64", name="nvi" 315 ) --> 316 self._nvi.iloc[0] = 1000 317 for i in range(1, len(self._nvi)): 318 if vol_decrease.iloc[i]:

c:\users\jeeva\documents\py_projects\general\lib\site-packages\pandas\core\indexing.py in setitem(self, key, value) 202 else: 203 key = com.apply_if_callable(key, self.obj) --> 204 indexer = self._get_setitem_indexer(key) 205 self._setitem_with_indexer(indexer, value) 206

c:\users\jeeva\documents\py_projects\general\lib\site-packages\pandas\core\indexing.py in _get_setitem_indexer(self, key) 189 axis = self.axis or 0 190 try: --> 191 return self._convert_to_indexer(key, axis=axis, is_setter=True) 192 except TypeError as e: 193

c:\users\jeeva\documents\py_projects\general\lib\site-packages\pandas\core\indexing.py in _convert_to_indexer(self, obj, axis, is_setter, raise_missing) 2173 2174 try: -> 2175 self._validate_key(obj, axis) 2176 return obj 2177 except ValueError:

c:\users\jeeva\documents\py_projects\general\lib\site-packages\pandas\core\indexing.py in _validate_key(self, key, axis) 2012 return 2013 elif is_integer(key): -> 2014 self._validate_integer(key, axis) 2015 elif isinstance(key, tuple): 2016 # a tuple should already have been caught by this point

c:\users\jeeva\documents\py_projects\general\lib\site-packages\pandas\core\indexing.py in _validate_integer(self, key, axis) 2086 len_axis = len(self.obj._get_axis(axis)) 2087 if key >= len_axis or key < -len_axis: -> 2088 raise IndexError("single positional indexer is out-of-bounds") 2089 2090 def _getitem_tuple(self, tup):

IndexError: single positional indexer is out-of-bounds

Jeevan-J avatar Dec 06 '20 17:12 Jeevan-J

We are getting this error not only in add_volume_ta, but in many other functions as well.

Jeevan-J avatar Dec 06 '20 17:12 Jeevan-J

Hey @Jeevan-J ,

I cannot reproduce your error. Please, share with me your Python version:

python -V

and the packages installed in your environment:

pip freeze

Also, if you can share with me a subsample of your dataset.

Best, Dario

bukosabino avatar Dec 07 '20 11:12 bukosabino

Hi,

Adding the python version and package list below along with the file I have used.

Python Version

(general) C:\Users\jeeva\Documents\Py_Projects>python -V Python 3.6.8

Package List

(general) C:\Users\jeeva\Documents\Py_Projects>pip freeze WARNING: Could not generate requirement for distribution -2o 3.30.0.4 (c:\users\jeeva\documents\py_projects\general\lib\site-packages): Parse error at "'-2o==3.3'": Expected W:(abcd...) WARNING: Could not generate requirement for distribution -atplotlib 3.2.2 (c:\users\jeeva\documents\py_projects\general\lib\site-packages): Parse error at "'-atplotl'": Expected W:(abcd...) absl-py==0.9.0 adal==1.2.4 aiofiles==0.5.0 aiohttp==3.6.2 alabaster==0.7.12 alembic==1.4.2 altair==4.1.0 altgraph==0.17 antlr4-python3-runtime==4.8 apispec==1.3.3 appdirs==1.4.3 APScheduler==3.6.3 argcomplete==1.11.1 arrow==0.16.0 asn1crypto==1.4.0 astor==0.8.1 astroid==2.4.1 astropy==4.0.1.post1 astunparse==1.6.3 async-generator==1.10 async-timeout==3.0.1 atomicwrites==1.4.0 attrs==19.3.0 Augmentor==0.2.8 autobahn==20.6.2 autoenv==1.0.0 Automat==20.2.0 awscli==1.18.84 azure-common==1.1.25 azure-mgmt-datalake-analytics==0.2.0 azure-mgmt-datalake-nspkg==3.0.1 azure-mgmt-nspkg==3.0.2 azure-nspkg==3.0.2 azure-storage-blob==2.1.0 azure-storage-common==2.1.0 Babel==2.8.0 backcall==0.1.0 bandit==1.6.2 base58==2.0.1 beautifulsoup4==4.9.0 binaryornot==0.4.4 black==20.8b1 bleach==3.1.4 blinker==1.4 blis==0.4.1 boto==2.49.0 boto3==1.10.50 botocore==1.13.50 briefcase==0.3.3 Brotli==1.0.7 cached-property==1.5.1 cachelib==0.1.1 cachetools==4.1.0 catalogue==1.0.0 catboost==0.20.2 cattrs==0.9.0 certifi==2020.4.5.1 cffi==1.14.0 chainer==7.7.0 chainercv==0.13.1 chardet==3.0.4 chart-studio==1.1.0 cliar==1.3.4 click==7.1.2 cloudpickle==1.3.0 colorama==0.4.3 colorclass==2.2.0 coloredlogs==10.0 colorhash==1.0.2 colorlog==4.0.2 colorlover==0.3.0 combo==0.1.0 configparser==3.5.3 confluent-kafka==1.5.0 confuse==1.1.0 constantly==15.1.0 contextvars==2.4 cookiecutter==1.7.2 coverage==4.5.4 coveralls==1.8.2 croniter==0.3.31 cryptography==2.9.2 cufflinks==0.17.0 cycler==0.10.0 cymem==2.0.3 Cython==0.29.14 dash==1.14.0 dash-core-components==1.10.2 dash-daq==0.5.0 dash-html-components==1.0.3 dash-renderer==1.6.0 dash-table==4.9.0 dask==2.27.0 databricks-cli==0.11.0 dataclasses==0.7 datefinder==0.7.0 dateparser==0.7.6 DateTime==4.3 decorator==4.4.2 defusedxml==0.6.0 Deprecated==1.2.10 dill==0.3.1.1 discord==1.0.1 discord.py==1.3.4 distributed==2.27.0 dnspython==1.16.0 docker==4.2.1 docopt==0.6.2 docutils==0.15.2 dodgy==0.2.1 entrypoints==0.3 enum-compat==0.0.3 et-xmlfile==1.0.1 eventlet==0.25.2 examl-exafluence==0.0.5 fastapi==0.58.0 fbmessenger==6.0.0 ffmpeg==1.4 ffmpeg-python==0.2.0 filelock==3.0.12 flake8==3.8.4 flake8-polyfill==1.0.2 Flask==1.1.2 Flask-Admin==1.5.4 Flask-AppBuilder==2.3.2 Flask-Babel==1.0.0 Flask-Caching==1.9.0 Flask-Compress==1.5.0 Flask-Cors==3.0.8 Flask-JWT-Extended==3.24.1 Flask-Login==0.4.1 Flask-Mail==0.9.1 Flask-Migrate==2.5.3 Flask-OpenID==1.2.5 Flask-Session==0.3.2 Flask-SQLAlchemy==2.4.1 flask-swagger==0.2.13 Flask-WTF==0.14.3 foliant==1.0.11 foliantcontrib.imagemagick==1.0.2 funcsigs==1.0.2 funcy==1.14 future==0.18.2 fuzzywuzzy==0.18.0 gast==0.3.3 gensim==3.8.3 gevent==1.5.0 gitdb==4.0.5 GitPython==3.1.3 google==2.0.3 google-api-core==1.19.0 google-api-python-client==1.9.1 google-auth==1.16.1 google-auth-httplib2==0.0.3 google-auth-oauthlib==0.4.1 google-cloud-core==1.3.0 google-cloud-storage==1.29.0 google-pasta==0.2.0 google-resumable-media==0.5.1 googleapis-common-protos==1.52.0 gorilla==0.3.0 graphviz==0.13.2 greenlet==0.4.15 grpcio==1.28.1 gunicorn==20.0.4 h11==0.8.1 h2==3.0.1 h2o @ http://h2o-release.s3.amazonaws.com/h2o/rel-zeno/2/Python/h2o-3.30.1.2-py2.py3-none-any.whl h5py==2.10.0 hdbcli==2.4.194 HeapDict==1.0.1 hpack==3.0.0 hstspreload==2020.5.19 htmlmin==0.1.12 httplib2==0.18.1 httptools==0.1.1 httpx==0.9.3 humanfriendly==8.2 hyperframe==5.2.0 hyperlink==19.0.0 idna==2.8 idna-ssl==1.1.0 ijson==3.1.1 ImageHash==4.1.0 imageio==2.9.0 imagesize==1.2.0 immutables==0.14 importlib-metadata==3.1.1 incremental==17.5.0 ipykernel==5.2.1 ipython==7.13.0 ipython-genutils==0.2.0 ipywidgets==7.5.1 iso8601==0.1.12 isodate==0.6.0 isort==4.3.21 itsdangerous==0.24 JayDeBeApi==1.1.1 jdcal==1.4.1 jedi==0.17.0 Jinja2==2.11.2 jinja2-time==0.2.0 jmespath==0.10.0 joblib==0.15.1 JPype1==0.7.1 json-merge-patch==0.2 json5==0.9.5 jsonpickle==1.4.1 jsonschema==3.2.0 jupyter==1.0.0 jupyter-client==6.1.3 jupyter-console==6.1.0 jupyter-core==4.6.3 jupyterlab==1.2.3 jupyterlab-server==1.0.9 kafka-python==1.4.7 Keras==2.4.3 Keras-Applications==1.0.8 Keras-Preprocessing==1.1.0 keyring==21.2.1 kfp==0.5.1 kfp-server-api==0.5.0 kiwisolver==1.2.0 kmodes==0.10.1 kubernetes==11.0.0 lazy-object-proxy==1.4.3 lightgbm==2.3.1 llvmlite==0.32.1 lockfile==0.12.2 lxml==4.5.0 m3u8==0.6.0 magickwand==0.2 mailer==0.8.1 Mako==1.1.2 Markdown==2.6.11 MarkupSafe==1.0 marshmallow==3.8.0 marshmallow-enum==1.5.1 marshmallow-oneofschema==2.0.1 marshmallow-sqlalchemy==0.22.3 matplotlib==3.1.1 mattermostwrapper==2.2 mccabe==0.6.1 missingno==0.4.2 mistune==0.8.4 mlflow==1.8.0 mlrun==0.4.10 mlxtend==0.17.2 monotonic==1.5 more-itertools==8.2.0 MouseInfo==0.1.3 msal==1.4.1 msgpack==1.0.0 msrest==0.6.17 msrestazure==0.4.34 multidict==4.7.5 murmurhash==1.0.2 mypy==0.790 mypy-extensions==0.4.3 mysql-connector==2.2.9 nbconvert==5.6.1 nbformat==5.0.6 nest-asyncio==1.3.3 networkx==2.4 nltk==3.5 notebook==6.0.3 nuclio-jupyter==0.8.5 numba==0.49.1 numexpr==2.7.1 numpy==1.17.4 oauth2client==4.1.3 oauthlib==3.1.0 opencv-python==4.3.0.36 openpyxl==3.0.3 opt-einsum==3.2.1 oscrypto==1.2.1 packaging==19.0 pandas==0.25.3 pandas-profiling==2.8.0 pandocfilters==1.4.2 parso==0.7.0 pathspec==0.8.1 pathtools==0.1.2 pbr==5.5.1 pdfkit==0.6.1 pefile==2019.4.18 pendulum==2.1.2 pep8-naming==0.10.0 percy==2.0.2 perfect==0.0.1 phik==0.10.0 pickleshare==0.7.5 pika==1.1.0 Pillow==7.1.2 pkginfo==1.5.0.1 plac==1.1.3 plotly==4.4.1 pluggy==0.13.1 poyo==0.5.0 prefect==0.13.8 preshed==3.0.2 prison==0.1.3 prometheus-client==0.7.1 prometheus-flask-exporter==0.14.1 prompt-toolkit==2.0.10 prospector==1.3.1 protobuf==3.11.3 psutil==5.7.0 psycopg2-binary==2.8.5 py==1.8.1 py4j==0.10.9 pyarrow==0.17.1 pyasn1==0.4.8 pyasn1-modules==0.2.8 PyAutoGUI==0.9.52 pybinding==0.9.4 pycaret==1.0.0 pycodestyle==2.6.0 pycparser==2.20 pycryptodomex==3.9.8 pydantic==1.5.1 pydeck==0.4.0b2 pydicom==1.4.2 pydocstyle==5.1.1 pydot==1.4.1 pyflakes==2.2.0 PyGetWindow==0.0.9 Pygments==2.6.1 PyHamcrest==2.0.2 PyInstaller==3.6 PyJWT==1.7.1 pykwalify==1.7.0 pyLDAvis==2.1.2 pylint==2.5.3 pylint-celery==0.3 pylint-django==2.1.0 pylint-flask==0.6 pylint-plugin-utils==0.6 pymongo==3.8.0 PyMsgBox==1.0.9 PyNaCl==1.3.0 pyod==0.8.0 pyodbc==4.0.30 pyOpenSSL==19.1.0 pyparsing==2.2.0 pyperclip==1.8.1 pypiwin32==223 pyreadline==2.1 PyRect==0.1.4 pyrsistent==0.16.0 PyScreeze==0.1.26 PySocks==1.7.1 pyspark==3.0.0 pytest==5.4.1 pytest-mock==3.1.0 pytest-sugar==0.9.3 python-binance==0.7.5 python-box==5.1.1 python-crfsuite==0.9.7 python-daemon==2.1.2 python-dateutil==2.8.1 python-dotenv==0.14.0 python-editor==1.0.4 python-engineio==3.12.1 python-slugify==4.0.1 python-socketio==4.5.1 python-telegram-bot==12.7 python3-openid==3.1.0 pythonnet==2.5.1 PyTweening==1.0.3 pytz==2019.3 pytzdata==2020.1 PyWavelets==1.1.1 pywhatkit==3.2 pywin32==227 pywin32-ctypes==0.2.0 pywinpty==0.5.7 PyYAML==5.3.1 pyzmq==19.0.0 qtconsole==4.7.3 QtPy==1.9.0 querystring-parser==1.2.4 questionary==1.5.2 rasa==1.10.1 rasa-sdk==1.10.1 readme-renderer==26.0 redis==3.5.2 regex==2020.5.14 requests==2.22.0 requests-oauthlib==1.3.0 requests-toolbelt==0.9.1 requirements-detector==0.7 retrying==1.3.3 rfc3986==1.4.0 rocketchat-API==1.3.1 rsa==3.4.2 ruamel.yaml==0.16.10 ruamel.yaml.clib==0.2.0 s3transfer==0.2.1 sacremoses==0.0.43 sanic==19.12.2 Sanic-Cors==0.10.0.post3 sanic-jwt==1.4.1 Sanic-Plugins-Framework==0.9.2 scikit-learn==0.22 scipy==1.4.1 seaborn==0.10.1 selenium==3.141.0 Send2Trash==1.5.0 sentencepiece==0.1.91 service-identity==18.1.0 setoptconf==0.2.0 setproctitle==1.1.10 shap==0.32.1 simple-http-server==0.1.7 simplejson==3.17.0 six==1.14.0 sklearn-crfsuite==0.3.6 slackclient==2.6.0 smart-open==2.0.0 smmap==3.0.4 sniffio==1.1.0 snowballstemmer==2.0.0 snowflake-connector-python==2.0.4 sortedcontainers==2.2.2 soupsieve==2.0 spacy==2.3.0 Sphinx==2.2.1 sphinx-rtd-theme==0.4.3 sphinxcontrib-applehelp==1.0.2 sphinxcontrib-devhelp==1.0.2 sphinxcontrib-htmlhelp==1.0.3 sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.3 sphinxcontrib-serializinghtml==1.1.4 SQLAlchemy==1.3.13 SQLAlchemy-JSONField==0.9.0 SQLAlchemy-Utils==0.36.3 sqlparse==0.3.1 srsly==1.0.2 starlette==0.13.4 stevedore==3.3.0 streamlit==0.61.0 strip-hints==0.1.9 suod==0.0.4 ta==0.7.0 tabulate==0.8.3 tangled-up-in-unicode==0.0.6 tbb==2019.0 tblib==1.7.0 tenacity==4.12.0 tensorboard==2.2.2 tensorboard-plugin-wit==1.7.0 tensorflow==2.2.0 tensorflow-addons==0.7.1 tensorflow-estimator==2.2.0 tensorflow-hub==0.8.0 tensorflow-probability==0.9.0 termcolor==1.1.0 terminado==0.8.3 terminaltables==3.1.0 testpath==0.4.4 text-unidecode==1.3 textblob==0.15.3 Theano==1.0.4 thinc==7.4.1 thrift==0.13.0 tld==0.12.2 toga-core==0.3.0.dev23 toga-winforms==0.3.0.dev23 tokenizers==0.7.0 toml==0.10.1 toolz==0.10.0 torch==1.5.0 torchvision==0.6.0 tornado==5.1.1 tqdm==4.45.0 traitlets==4.3.3 transformers==2.10.0 travertino==0.1.3 twilio==6.26.3 twine==3.1.1 Twisted==20.3.0 txaio==20.4.1 typed-ast==1.4.1 typing==3.7.4.1 typing-extensions==3.7.4.2 tzlocal==1.5.1 ujson==2.0.3 umap-learn==0.4.4 unicodecsv==0.14.1 uritemplate==3.0.1 urllib3==1.24.3 uvicorn==0.11.5 v3io==0.3.16 validators==0.15.0 visions==0.4.4 waitress==1.4.3 wasabi==0.6.0 watchdog==0.10.2 wcwidth==0.1.9 webencodings==0.5.1 webexteamssdk==1.3 websocket-client==0.57.0 websockets==8.1 Werkzeug==1.0.1 widgetsnbextension==3.5.1 wikipedia==1.4.0 wordcloud==1.7.0 wptserve==3.0 wrapt==1.12.1 WTForms==2.2.1 xgboost==0.90 xlrd==1.2.0 XlsxWriter==1.3.7 xmltodict==0.12.0 yarl==1.4.2 yellowbrick==1.0.1 youtube-dl==2020.3.24 zict==2.0.0 zipp==3.1.0 zope.deprecation==4.4.0 zope.interface==5.1.0

Files used: XRPUSDT.zip

Jeevan-J avatar Dec 08 '20 06:12 Jeevan-J

Hi,

Any update on this issue?

Thanks

gteindia avatar Mar 15 '21 01:03 gteindia