alvarobartt / investpy

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

search_quotes returns unconsistent type #339

Closed tavasti closed 3 years ago

tavasti commented 3 years ago

Thanks for fixing search_quotes back to live quickly!

However, there is one more thing in it:

search_quotes returns list when getting multiple entries, but single object when there is only one:

>>> import investpy
>>> df1 = investpy.search_quotes('LU0486851024',products=["etfs"],countries=["germany"])
>>> df2 = investpy.search_quotes('IE00BFNM3P36',products=["etfs"],countries=["germany"])
>>> df1
<investpy.utils.search_obj.SearchObj object at 0x7f9de7120198>
>>> df2
[<investpy.utils.search_obj.SearchObj object at 0x7f9de711e710>, <investpy.utils.search_obj.SearchObj object at 0x7f9de711e748>, <investpy.utils.search_obj.SearchObj object at 0x7f9de711e780>]

Should it return list in any case?

alvarobartt commented 3 years ago

Hi @tavasti, thank you too for reporting the issues! :fire:

Indeed I included an option so that whenever the parameter n_results is 1, instead of returning a list with just one SearchObj, just the SearchObj is returned. Anyway, it seems that I need to include another if-statement so as to just proceed with this approach whenever n_results=1, and not whenever there's just one result, which is not the same.

Thank you for reporting this too!

alvarobartt commented 3 years ago

P.S.: As a quick fix you can just

result = results[0] if isinstance(results, list) else results
tavasti commented 3 years ago

P.S.: As a quick fix you can just

result = results[0] if isinstance(results, list) else results

Yeah, that is what I did, but still wanted to report this because most likely there will be other people who hit the same.

alvarobartt commented 3 years ago

Hi again @tavasti I'll be fixing this so that it just returns a single value if n_results=1 otherwise it will return a list even if that list just contains a single value, should that fix the issue/bug? Thanks!

tavasti commented 3 years ago

Yeah, that sounds correct!

alvarobartt commented 3 years ago

Hi @tavasti this has already been solved! :fire: So the current behaviour is:

>>> import investpy
>>> data = investpy.search_quotes('LU0486851024',products=["etfs"],countries=["germany"])
>>> data
[<investpy.utils.search_obj.SearchObj object at 0x7fd8e28d53d0>]
>>> data = investpy.search_quotes('LU0486851024',products=["etfs"],countries=["germany"], n_results=1)
>>> data
<investpy.utils.search_obj.SearchObj object at 0x7fd8e28d5370>

This will be available in the next release investpy v1.0.7 later this weekend once I complete all the issues included in the current milestone! :balloon:

alvarobartt commented 3 years ago

Hi @tavasti, the new release is already out! :fire:

You can already install it using either pip install investpy==1.0.7 or just update the current version that you are using with pip install investpy --upgrade. Thanks a lot for your support! :+1:

For more information about this new release, you should check investpy v1.0.7 Release :balloon: