ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
14.89k stars 2.44k forks source link

0.2.47 Refactor multi.py to return single-level index when a single ticker #2100

Closed BiggRanger closed 3 weeks ago

BiggRanger commented 3 weeks ago

Describe bug

Refactoring multi.py to return single-level indexes when using a single ticker is breaking a lot of existing code in several applications. Was this refactor necessary?

Debug log

No response

yfinance version

0.2.47

Python version

3.10

Operating system

kubuntu 22.04

ValueRaider commented 3 weeks ago

It was changed here #2068. And their argument makes sense - if the calling code always expects just one ticker, then use Ticker.history. Then code that calls download and expects a MultiIndex always gets it, no special case needed. @ranaroussi @antoniouaa

ranaroussi commented 3 weeks ago

I've pushed a new version that will address both cases (I actually had cases where the new approach broke things).

I've added multi_level_index parameter to multi.py with a default value to True. If set to False and only one ticker is requested - the returned DataFrame will be single-level-index. If not specified, or specified as True - a multi-level index will be returned regardless.