Repository: ranaroussi/yfinance

Issue:
TypeError("unsupported operand type(s) for -: 'str' and 'int'") when downloading price data
The ```yf.download``` method does not seem to be working as of late for me, it gives me the error: ```TypeError("unsupported operand type(s) for -: 'str' and 'int'")``` when download stock data with ``period='max'`` or with ``start`` and ``end`` parameters.

---

To prove this was not an error on my end, I followed the example in the documentation:
![image](https://user-images.githubusercontent.com/107745404/232230323-c1de53a3-44ce-4579-a3c2-0cb786f8d870.png)
![image](https://user-images.githubusercontent.com/107745404/232315400-5bb58b48-e1c0-4c9d-b787-fa0ec4874c13.png)

And here was the output (imported yfinance as yf):
```
2 Failed downloads:
- AAPL: TypeError("unsupported operand type(s) for -: 'str' and 'int'")
AAPL: Traceback (most recent call last):
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\pandas\io\parsers\c_parser_wrapper.py", line 230, in read
    chunks = self._reader.read_low_memory(nrows)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pandas\_libs\parsers.pyx", line 833, in pandas._libs.parsers.TextReader.read_low_memory
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\yfinance\multi.py", line 225, in _download_one_threaded
    data = _download_one(ticker, start, end, auto_adjust, back_adjust, repair,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\yfinance\multi.py", line 244, in _download_one
    return Ticker(ticker).history(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\yfinance\base.py", line 154, in history
    tz = self._get_ticker_tz(proxy, timeout)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\yfinance\base.py", line 930, in _get_ticker_tz
    cache = utils.get_tz_cache()
            ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\yfinance\utils.py", line 967, in get_tz_cache
    _tz_cache = _TzCache()
                ^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\yfinance\utils.py", line 893, in __init__
    self._migrate_cache_tkr_tz()
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\yfinance\utils.py", line 934, in _migrate_cache_tkr_tz
    df = _pd.read_csv(old_cache_file_path, index_col="Ticker")
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\pandas\util\_decorators.py", line 211, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\pandas\util\_decorators.py", line 331, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\pandas\io\parsers\readers.py", line 950, in read_csv
    return _read(filepath_or_buffer, kwds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\pandas\io\parsers\readers.py", line 611, in _read
    return parser.read(nrows)
           ^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\pandas\io\parsers\readers.py", line 1778, in read
    ) = self._engine.read(  # type: ignore[attr-defined]
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\pandas\io\parsers\c_parser_wrapper.py", line 240, in read
    index, columns, col_dict = self._get_empty_meta(
                               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\pandas\io\parsers\base_parser.py", line 1047, in _get_empty_meta
    columns.pop(n - i)
                ~~^~~
TypeError: unsupported operand type(s) for -: 'str' and 'int'

- SPY: TypeError("unsupported operand type(s) for -: 'str' and 'int'")
SPY: Traceback (most recent call last):
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\pandas\io\parsers\c_parser_wrapper.py", line 230, in read
    chunks = self._reader.read_low_memory(nrows)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pandas\_libs\parsers.pyx", line 833, in pandas._libs.parsers.TextReader.read_low_memory
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\yfinance\multi.py", line 225, in _download_one_threaded
    data = _download_one(ticker, start, end, auto_adjust, back_adjust, repair,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\yfinance\multi.py", line 244, in _download_one
    return Ticker(ticker).history(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\yfinance\base.py", line 154, in history
    tz = self._get_ticker_tz(proxy, timeout)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\yfinance\base.py", line 930, in _get_ticker_tz
    cache = utils.get_tz_cache()
            ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\yfinance\utils.py", line 967, in get_tz_cache
    _tz_cache = _TzCache()
                ^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\yfinance\utils.py", line 893, in __init__
    self._migrate_cache_tkr_tz()
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\yfinance\utils.py", line 934, in _migrate_cache_tkr_tz
    df = _pd.read_csv(old_cache_file_path, index_col="Ticker")
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\pandas\util\_decorators.py", line 211, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\pandas\util\_decorators.py", line 331, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\pandas\io\parsers\readers.py", line 950, in read_csv
    return _read(filepath_or_buffer, kwds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\pandas\io\parsers\readers.py", line 611, in _read
    return parser.read(nrows)
           ^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\pandas\io\parsers\readers.py", line 1778, in read
    ) = self._engine.read(  # type: ignore[attr-defined]
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\pandas\io\parsers\c_parser_wrapper.py", line 240, in read
    index, columns, col_dict = self._get_empty_meta(
                               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\AppData\Roaming\Python\Python311\site-packages\pandas\io\parsers\base_parser.py", line 1047, in _get_empty_meta
    columns.pop(n - i)
                ~~^~~
TypeError: unsupported operand type(s) for -: 'str' and 'int'
```


Has anyone else been experiencing this issue? Is this a problem on yfinance's end? How can this be resolved?

Thanks

_Originally posted by @dippudo in https://github.com/ranaroussi/yfinance/discussions/1495_


Discussion:

Resolving patch:
diff --git a/yfinance/utils.py b/yfinance/utils.py
--- a/yfinance/utils.py
+++ b/yfinance/utils.py
@@ -920,6 +920,8 @@ def _migrate_cache_tkr_tz(self):
             df = _pd.read_csv(old_cache_file_path, index_col="Ticker")
         except _pd.errors.EmptyDataError:
             _os.remove(old_cache_file_path)
+        except TypeError:
+            _os.remove(old_cache_file_path)
         else:
             self.tz_db.bulk_set(df.to_dict()['Tz'])
             _os.remove(old_cache_file_path)


Test patch: