Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search_quotes returns unconsistent type #339

Closed
tavasti opened this issue Apr 11, 2021 · 7 comments
Closed

search_quotes returns unconsistent type #339

tavasti opened this issue Apr 11, 2021 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@tavasti
Copy link

tavasti commented Apr 11, 2021

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 alvarobartt self-assigned this Apr 11, 2021
@alvarobartt alvarobartt added the bug Something isn't working label Apr 11, 2021
@alvarobartt
Copy link
Owner

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

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
Copy link
Owner

alvarobartt commented Apr 11, 2021

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

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

@tavasti
Copy link
Author

tavasti commented Apr 11, 2021

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.

dennismatveev added a commit to AGoodGuy5543/investpy that referenced this issue Apr 15, 2021
@alvarobartt alvarobartt added this to the investpy v1.0.7 milestone Jun 9, 2021
@alvarobartt
Copy link
Owner

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
Copy link
Author

tavasti commented Jun 9, 2021

Yeah, that sounds correct!

@alvarobartt
Copy link
Owner

alvarobartt commented Jun 12, 2021

Hi @tavasti this has already been solved! 🔥 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! 🎈

@alvarobartt
Copy link
Owner

Hi @tavasti, the new release is already out! 🔥

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! 👍

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants