alvarobartt / investpy

Financial Data Extraction from Investing.com with Python
https://investpy.readthedocs.io/
MIT License
1.59k stars 375 forks source link

technical.moving_averages: Getting the error at the request for Canada #346

Closed guberm closed 3 years ago

guberm commented 3 years ago

Request: investpy.technical.moving_averages(name='WELL', country='Canada', product_type='stock', interval='daily')

Error: Exception has occurred: AttributeError 'float' object has no attribute 'encode'

** For the United States is working correctly

alvarobartt commented 3 years ago

Hi @guberm, thanks for the report, I'll check this now! :fire:

alvarobartt commented 3 years ago

Ok, I've already solved this, as the issue was happening since there's a Canadian stock with the symbol NA so that the pandas function to read the CSV was interpreting the NA value as an np.nan. So on, the function was failing while trying to later apply unidecode over a column where not all the values are strings since NaN is float.

This was reported a while ago in https://github.com/alvarobartt/investpy/issues/180, and then solved, but it seems that I just solved it for the stocks.csv file reading, but not the generic one, so the issue was still happening when using stock functions outside stocks.py.

So on, before the investpy v1.0.7 release comes out you can install the latest working version as it follows:

pip install git+https://github.com/alvarobartt/investpy.git@master

Thank you again! :+1:

guberm commented 3 years ago

I did the update, but still getting the error :-( sorry for that

I'm not sure if that relevant, but you didn't update technical.py and stock.py

image

Traceback (most recent call last): File "c:\Users\michael.guber\Desktop\investpy0.py", line 48, in <module> techData = get_stock_tech_data(stock_symb, intervalS, type, countryS) File "c:\Users\michael.guber\Desktop\investpy0.py", line 40, in get_stock_tech_data techData = investpy.technical.moving_averages(name='WELL', country='Canada', product_type='stock', interval='daily') File "c:\users\michael.guber\appdata\local\programs\python\python39\lib\site-packages\investpy\technical.py", line 273, in moving_averages if name not in list(data[check].apply(unidecode).str.lower()): File "c:\users\michael.guber\appdata\local\programs\python\python39\lib\site-packages\pandas-1.2.3-py3.9-win-amd64.egg\pandas\core\series.py", line 4138, in apply mapped = lib.map_infer(values, f, convert=convert_dtype) File "pandas\_libs\lib.pyx", line 2467, in pandas._libs.lib.map_infer File "c:\users\michael.guber\appdata\local\programs\python\python39\lib\site-packages\unidecode-1.2.0-py3.9.egg\unidecode\__init__.py", line 66, in unidecode_expect_ascii bytestring = string.encode('ASCII') AttributeError: 'float' object has no attribute 'encode'

Thank you for your work