We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Timezone value passed on to the option_chain throws TypeError
ticker.option_chain(date='2021-11-26', tz="UTC")

TypeError : index is not a valid DatetimeIndex or PeriodIndex


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `yfinance/ticker.py`
Content:
```
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # yfinance - market data downloader
5 # https://github.com/ranaroussi/yfinance
6 #
7 # Copyright 2017-2019 Ran Aroussi
8 #
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
12 #
13 #     http://www.apache.org/licenses/LICENSE-2.0
14 #
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 #
21 
22 from __future__ import print_function
23 
24 # import time as _time
25 import datetime as _datetime
26 import requests as _requests
27 import pandas as _pd
28 # import numpy as _np
29 
30 # import json as _json
31 # import re as _re
32 from collections import namedtuple as _namedtuple
33 
34 from . import utils
35 from .base import TickerBase
36 
37 
38 class Ticker(TickerBase):
39 
40     def __repr__(self):
41         return 'yfinance.Ticker object <%s>' % self.ticker
42 
43     def _download_options(self, date=None, proxy=None):
44         if date is None:
45             url = "{}/v7/finance/options/{}".format(
46                 self._base_url, self.ticker)
47         else:
48             url = "{}/v7/finance/options/{}?date={}".format(
49                 self._base_url, self.ticker, date)
50 
51         # setup proxy in requests format
52         if proxy is not None:
53             if isinstance(proxy, dict) and "https" in proxy:
54                 proxy = proxy["https"]
55             proxy = {"https": proxy}
56 
57         r = _requests.get(
58             url=url,
59             proxies=proxy,
60             headers=utils.user_agent_headers
61         ).json()
62         if len(r.get('optionChain', {}).get('result', [])) > 0:
63             for exp in r['optionChain']['result'][0]['expirationDates']:
64                 self._expirations[_datetime.datetime.utcfromtimestamp(
65                     exp).strftime('%Y-%m-%d')] = exp
66             opt = r['optionChain']['result'][0].get('options', [])
67             return opt[0] if len(opt) > 0 else []
68 
69     def _options2df(self, opt, tz=None):
70         data = _pd.DataFrame(opt).reindex(columns=[
71             'contractSymbol',
72             'lastTradeDate',
73             'strike',
74             'lastPrice',
75             'bid',
76             'ask',
77             'change',
78             'percentChange',
79             'volume',
80             'openInterest',
81             'impliedVolatility',
82             'inTheMoney',
83             'contractSize',
84             'currency'])
85 
86         data['lastTradeDate'] = _pd.to_datetime(
87             data['lastTradeDate'], unit='s')
88         if tz is not None:
89             data['lastTradeDate'] = data['lastTradeDate'].tz_localize(tz)
90         return data
91 
92     def option_chain(self, date=None, proxy=None, tz=None):
93         if date is None:
94             options = self._download_options(proxy=proxy)
95         else:
96             if not self._expirations:
97                 self._download_options()
98             if date not in self._expirations:
99                 raise ValueError(
100                     "Expiration `%s` cannot be found. "
101                     "Available expiration are: [%s]" % (
102                         date, ', '.join(self._expirations)))
103             date = self._expirations[date]
104             options = self._download_options(date, proxy=proxy)
105 
106         return _namedtuple('Options', ['calls', 'puts'])(**{
107             "calls": self._options2df(options['calls'], tz=tz),
108             "puts": self._options2df(options['puts'], tz=tz)
109         })
110 
111     # ------------------------
112 
113     @property
114     def isin(self):
115         return self.get_isin()
116 
117     @property
118     def major_holders(self):
119         return self.get_major_holders()
120 
121     @property
122     def institutional_holders(self):
123         return self.get_institutional_holders()
124 
125     @property
126     def mutualfund_holders(self):
127         return self.get_mutualfund_holders()
128 
129     @property
130     def dividends(self):
131         return self.get_dividends()
132 
133     @property
134     def splits(self):
135         return self.get_splits()
136 
137     @property
138     def actions(self):
139         return self.get_actions()
140 
141     @property
142     def info(self):
143         return self.get_info()
144 
145     @property
146     def calendar(self):
147         return self.get_calendar()
148 
149     @property
150     def recommendations(self):
151         return self.get_recommendations()
152 
153     @property
154     def earnings(self):
155         return self.get_earnings()
156 
157     @property
158     def quarterly_earnings(self):
159         return self.get_earnings(freq='quarterly')
160 
161     @property
162     def financials(self):
163         return self.get_financials()
164 
165     @property
166     def quarterly_financials(self):
167         return self.get_financials(freq='quarterly')
168 
169     @property
170     def balance_sheet(self):
171         return self.get_balancesheet()
172 
173     @property
174     def quarterly_balance_sheet(self):
175         return self.get_balancesheet(freq='quarterly')
176 
177     @property
178     def balancesheet(self):
179         return self.get_balancesheet()
180 
181     @property
182     def quarterly_balancesheet(self):
183         return self.get_balancesheet(freq='quarterly')
184 
185     @property
186     def cashflow(self):
187         return self.get_cashflow()
188 
189     @property
190     def quarterly_cashflow(self):
191         return self.get_cashflow(freq='quarterly')
192 
193     @property
194     def sustainability(self):
195         return self.get_sustainability()
196 
197     @property
198     def options(self):
199         if not self._expirations:
200             self._download_options()
201         return tuple(self._expirations.keys())
202 
203     @property
204     def news(self):
205         return self.get_news()
206 
207     @property
208     def analysis(self):
209         return self.get_analysis()
210
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/yfinance/ticker.py b/yfinance/ticker.py
--- a/yfinance/ticker.py
+++ b/yfinance/ticker.py
@@ -84,9 +84,9 @@
             'currency'])
 
         data['lastTradeDate'] = _pd.to_datetime(
-            data['lastTradeDate'], unit='s')
+            data['lastTradeDate'], unit='s', utc=True)
         if tz is not None:
-            data['lastTradeDate'] = data['lastTradeDate'].tz_localize(tz)
+            data['lastTradeDate'] = data['lastTradeDate'].dt.tz_convert(tz)
         return data
 
     def option_chain(self, date=None, proxy=None, tz=None):

{"golden_diff": "diff --git a/yfinance/ticker.py b/yfinance/ticker.py\n--- a/yfinance/ticker.py\n+++ b/yfinance/ticker.py\n@@ -84,9 +84,9 @@\n             'currency'])\n \n         data['lastTradeDate'] = _pd.to_datetime(\n-            data['lastTradeDate'], unit='s')\n+            data['lastTradeDate'], unit='s', utc=True)\n         if tz is not None:\n-            data['lastTradeDate'] = data['lastTradeDate'].tz_localize(tz)\n+            data['lastTradeDate'] = data['lastTradeDate'].dt.tz_convert(tz)\n         return data\n \n     def option_chain(self, date=None, proxy=None, tz=None):\n", "issue": "Timezone value passed on to the option_chain throws TypeError\nticker.option_chain(date='2021-11-26', tz=\"UTC\")\r\n\r\nTypeError : index is not a valid DatetimeIndex or PeriodIndex\r\n\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# yfinance - market data downloader\n# https://github.com/ranaroussi/yfinance\n#\n# Copyright 2017-2019 Ran Aroussi\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n#\n\nfrom __future__ import print_function\n\n# import time as _time\nimport datetime as _datetime\nimport requests as _requests\nimport pandas as _pd\n# import numpy as _np\n\n# import json as _json\n# import re as _re\nfrom collections import namedtuple as _namedtuple\n\nfrom . import utils\nfrom .base import TickerBase\n\n\nclass Ticker(TickerBase):\n\n    def __repr__(self):\n        return 'yfinance.Ticker object <%s>' % self.ticker\n\n    def _download_options(self, date=None, proxy=None):\n        if date is None:\n            url = \"{}/v7/finance/options/{}\".format(\n                self._base_url, self.ticker)\n        else:\n            url = \"{}/v7/finance/options/{}?date={}\".format(\n                self._base_url, self.ticker, date)\n\n        # setup proxy in requests format\n        if proxy is not None:\n            if isinstance(proxy, dict) and \"https\" in proxy:\n                proxy = proxy[\"https\"]\n            proxy = {\"https\": proxy}\n\n        r = _requests.get(\n            url=url,\n            proxies=proxy,\n            headers=utils.user_agent_headers\n        ).json()\n        if len(r.get('optionChain', {}).get('result', [])) > 0:\n            for exp in r['optionChain']['result'][0]['expirationDates']:\n                self._expirations[_datetime.datetime.utcfromtimestamp(\n                    exp).strftime('%Y-%m-%d')] = exp\n            opt = r['optionChain']['result'][0].get('options', [])\n            return opt[0] if len(opt) > 0 else []\n\n    def _options2df(self, opt, tz=None):\n        data = _pd.DataFrame(opt).reindex(columns=[\n            'contractSymbol',\n            'lastTradeDate',\n            'strike',\n            'lastPrice',\n            'bid',\n            'ask',\n            'change',\n            'percentChange',\n            'volume',\n            'openInterest',\n            'impliedVolatility',\n            'inTheMoney',\n            'contractSize',\n            'currency'])\n\n        data['lastTradeDate'] = _pd.to_datetime(\n            data['lastTradeDate'], unit='s')\n        if tz is not None:\n            data['lastTradeDate'] = data['lastTradeDate'].tz_localize(tz)\n        return data\n\n    def option_chain(self, date=None, proxy=None, tz=None):\n        if date is None:\n            options = self._download_options(proxy=proxy)\n        else:\n            if not self._expirations:\n                self._download_options()\n            if date not in self._expirations:\n                raise ValueError(\n                    \"Expiration `%s` cannot be found. \"\n                    \"Available expiration are: [%s]\" % (\n                        date, ', '.join(self._expirations)))\n            date = self._expirations[date]\n            options = self._download_options(date, proxy=proxy)\n\n        return _namedtuple('Options', ['calls', 'puts'])(**{\n            \"calls\": self._options2df(options['calls'], tz=tz),\n            \"puts\": self._options2df(options['puts'], tz=tz)\n        })\n\n    # ------------------------\n\n    @property\n    def isin(self):\n        return self.get_isin()\n\n    @property\n    def major_holders(self):\n        return self.get_major_holders()\n\n    @property\n    def institutional_holders(self):\n        return self.get_institutional_holders()\n\n    @property\n    def mutualfund_holders(self):\n        return self.get_mutualfund_holders()\n\n    @property\n    def dividends(self):\n        return self.get_dividends()\n\n    @property\n    def splits(self):\n        return self.get_splits()\n\n    @property\n    def actions(self):\n        return self.get_actions()\n\n    @property\n    def info(self):\n        return self.get_info()\n\n    @property\n    def calendar(self):\n        return self.get_calendar()\n\n    @property\n    def recommendations(self):\n        return self.get_recommendations()\n\n    @property\n    def earnings(self):\n        return self.get_earnings()\n\n    @property\n    def quarterly_earnings(self):\n        return self.get_earnings(freq='quarterly')\n\n    @property\n    def financials(self):\n        return self.get_financials()\n\n    @property\n    def quarterly_financials(self):\n        return self.get_financials(freq='quarterly')\n\n    @property\n    def balance_sheet(self):\n        return self.get_balancesheet()\n\n    @property\n    def quarterly_balance_sheet(self):\n        return self.get_balancesheet(freq='quarterly')\n\n    @property\n    def balancesheet(self):\n        return self.get_balancesheet()\n\n    @property\n    def quarterly_balancesheet(self):\n        return self.get_balancesheet(freq='quarterly')\n\n    @property\n    def cashflow(self):\n        return self.get_cashflow()\n\n    @property\n    def quarterly_cashflow(self):\n        return self.get_cashflow(freq='quarterly')\n\n    @property\n    def sustainability(self):\n        return self.get_sustainability()\n\n    @property\n    def options(self):\n        if not self._expirations:\n            self._download_options()\n        return tuple(self._expirations.keys())\n\n    @property\n    def news(self):\n        return self.get_news()\n\n    @property\n    def analysis(self):\n        return self.get_analysis()\n", "path": "yfinance/ticker.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# yfinance - market data downloader\n# https://github.com/ranaroussi/yfinance\n#\n# Copyright 2017-2019 Ran Aroussi\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n#\n\nfrom __future__ import print_function\n\n# import time as _time\nimport datetime as _datetime\nimport requests as _requests\nimport pandas as _pd\n# import numpy as _np\n\n# import json as _json\n# import re as _re\nfrom collections import namedtuple as _namedtuple\n\nfrom . import utils\nfrom .base import TickerBase\n\n\nclass Ticker(TickerBase):\n\n    def __repr__(self):\n        return 'yfinance.Ticker object <%s>' % self.ticker\n\n    def _download_options(self, date=None, proxy=None):\n        if date is None:\n            url = \"{}/v7/finance/options/{}\".format(\n                self._base_url, self.ticker)\n        else:\n            url = \"{}/v7/finance/options/{}?date={}\".format(\n                self._base_url, self.ticker, date)\n\n        # setup proxy in requests format\n        if proxy is not None:\n            if isinstance(proxy, dict) and \"https\" in proxy:\n                proxy = proxy[\"https\"]\n            proxy = {\"https\": proxy}\n\n        r = _requests.get(\n            url=url,\n            proxies=proxy,\n            headers=utils.user_agent_headers\n        ).json()\n        if len(r.get('optionChain', {}).get('result', [])) > 0:\n            for exp in r['optionChain']['result'][0]['expirationDates']:\n                self._expirations[_datetime.datetime.utcfromtimestamp(\n                    exp).strftime('%Y-%m-%d')] = exp\n            opt = r['optionChain']['result'][0].get('options', [])\n            return opt[0] if len(opt) > 0 else []\n\n    def _options2df(self, opt, tz=None):\n        data = _pd.DataFrame(opt).reindex(columns=[\n            'contractSymbol',\n            'lastTradeDate',\n            'strike',\n            'lastPrice',\n            'bid',\n            'ask',\n            'change',\n            'percentChange',\n            'volume',\n            'openInterest',\n            'impliedVolatility',\n            'inTheMoney',\n            'contractSize',\n            'currency'])\n\n        data['lastTradeDate'] = _pd.to_datetime(\n            data['lastTradeDate'], unit='s', utc=True)\n        if tz is not None:\n            data['lastTradeDate'] = data['lastTradeDate'].dt.tz_convert(tz)\n        return data\n\n    def option_chain(self, date=None, proxy=None, tz=None):\n        if date is None:\n            options = self._download_options(proxy=proxy)\n        else:\n            if not self._expirations:\n                self._download_options()\n            if date not in self._expirations:\n                raise ValueError(\n                    \"Expiration `%s` cannot be found. \"\n                    \"Available expiration are: [%s]\" % (\n                        date, ', '.join(self._expirations)))\n            date = self._expirations[date]\n            options = self._download_options(date, proxy=proxy)\n\n        return _namedtuple('Options', ['calls', 'puts'])(**{\n            \"calls\": self._options2df(options['calls'], tz=tz),\n            \"puts\": self._options2df(options['puts'], tz=tz)\n        })\n\n    # ------------------------\n\n    @property\n    def isin(self):\n        return self.get_isin()\n\n    @property\n    def major_holders(self):\n        return self.get_major_holders()\n\n    @property\n    def institutional_holders(self):\n        return self.get_institutional_holders()\n\n    @property\n    def mutualfund_holders(self):\n        return self.get_mutualfund_holders()\n\n    @property\n    def dividends(self):\n        return self.get_dividends()\n\n    @property\n    def splits(self):\n        return self.get_splits()\n\n    @property\n    def actions(self):\n        return self.get_actions()\n\n    @property\n    def info(self):\n        return self.get_info()\n\n    @property\n    def calendar(self):\n        return self.get_calendar()\n\n    @property\n    def recommendations(self):\n        return self.get_recommendations()\n\n    @property\n    def earnings(self):\n        return self.get_earnings()\n\n    @property\n    def quarterly_earnings(self):\n        return self.get_earnings(freq='quarterly')\n\n    @property\n    def financials(self):\n        return self.get_financials()\n\n    @property\n    def quarterly_financials(self):\n        return self.get_financials(freq='quarterly')\n\n    @property\n    def balance_sheet(self):\n        return self.get_balancesheet()\n\n    @property\n    def quarterly_balance_sheet(self):\n        return self.get_balancesheet(freq='quarterly')\n\n    @property\n    def balancesheet(self):\n        return self.get_balancesheet()\n\n    @property\n    def quarterly_balancesheet(self):\n        return self.get_balancesheet(freq='quarterly')\n\n    @property\n    def cashflow(self):\n        return self.get_cashflow()\n\n    @property\n    def quarterly_cashflow(self):\n        return self.get_cashflow(freq='quarterly')\n\n    @property\n    def sustainability(self):\n        return self.get_sustainability()\n\n    @property\n    def options(self):\n        if not self._expirations:\n            self._download_options()\n        return tuple(self._expirations.keys())\n\n    @property\n    def news(self):\n        return self.get_news()\n\n    @property\n    def analysis(self):\n        return self.get_analysis()\n", "path": "yfinance/ticker.py"}]}