We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Unbound local error
**Your Environment**
anaconda 
* Python version: 3.7.4
* Pip version:19.2.2
* Operating system:Windows
* Python environment used (e.g. venv, conda): conda
* Mindsdb version you tried to install:1.6.15
* Additional info if applicable:

**Describe the bug**
got Unbound local error while running this example 
[https://github.com/ZoranPandovski/mindsdb-examples/tree/master/air_quality](https://github.com/ZoranPandovski/mindsdb-examples/tree/master/air_quality)
**To Reproduce**
Steps to reproduce the behavior, for example:
1. clone the repository
2. Run that example code in a jupyter notebook and you should see the error as presented in the screenshot.

**Expected behavior**
It should start the training.

**Additional context**
![1](https://user-images.githubusercontent.com/19743451/67293940-c7a91f00-f502-11e9-8601-eb8f98c914c4.PNG)
![2](https://user-images.githubusercontent.com/19743451/67293955-cbd53c80-f502-11e9-91e6-108cc96e1061.PNG)

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mindsdb/libs/data_sources/file_ds.py`
Content:
```
1 import re
2 from io import BytesIO, StringIO
3 import csv
4 import codecs
5 import json
6 import traceback
7 import codecs
8 
9 import pandas
10 from pandas.io.json import json_normalize
11 import requests
12 
13 from mindsdb.libs.data_types.data_source import DataSource
14 from mindsdb.libs.data_types.mindsdb_logger import log
15 
16 
17 class FileDS(DataSource):
18 
19     def cleanRow(self, row):
20         n_row = []
21         for cell in row:
22             if str(cell) in ['', ' ', '  ', 'NaN', 'nan', 'NA']:
23                 cell = None
24             n_row.append(cell)
25 
26         return n_row
27 
28     def _getDataIo(self, file):
29         """
30         This gets a file either url or local file and defiens what the format is as well as dialect
31         :param file: file path or url
32         :return: data_io, format, dialect
33         """
34 
35         ############
36         # get file as io object
37         ############
38 
39         data = BytesIO()
40 
41         # get data from either url or file load in memory
42         if file[:5] == 'http:' or file[:6] == 'https:':
43             r = requests.get(file, stream=True)
44             if r.status_code == 200:
45                 for chunk in r:
46                     data.write(chunk)
47             data.seek(0)
48 
49         # else read file from local file system
50         else:
51             try:
52                 data = open(file, 'rb')
53             except Exception as e:
54                 error = 'Could not load file, possible exception : {exception}'.format(exception = e)
55                 log.error(error)
56                 raise ValueError(error)
57 
58 
59         dialect = None
60 
61         ############
62         # check for file type
63         ############
64 
65         # try to guess if its an excel file
66         xlsx_sig = b'\x50\x4B\x05\06'
67         xlsx_sig2 = b'\x50\x4B\x03\x04'
68         xls_sig = b'\x09\x08\x10\x00\x00\x06\x05\x00'
69 
70         # different whence, offset, size for different types
71         excel_meta = [ ('xls', 0, 512, 8), ('xlsx', 2, -22, 4)]
72 
73         for filename, whence, offset, size in excel_meta:
74 
75             try:
76                 data.seek(offset, whence)  # Seek to the offset.
77                 bytes = data.read(size)  # Capture the specified number of bytes.
78                 data.seek(0)
79                 codecs.getencoder('hex')(bytes)
80 
81                 if bytes == xls_sig:
82                     return data, 'xls', dialect
83                 elif bytes == xlsx_sig:
84                     return data, 'xlsx', dialect
85 
86             except:
87                 data.seek(0)
88 
89         # if not excel it can be a json file or a CSV, convert from binary to stringio
90 
91         byte_str = data.read()
92         # Move it to StringIO
93         try:
94             # Handle Microsoft's BOM "special" UTF-8 encoding
95             if byte_str.startswith(codecs.BOM_UTF8):
96                 data = StringIO(byte_str.decode('utf-8-sig'))
97             else:
98                 data = StringIO(byte_str.decode('utf-8'))
99 
100         except:
101             log.error(traceback.format_exc())
102             log.error('Could not load into string')
103 
104         # see if its JSON
105         buffer = data.read(100)
106         data.seek(0)
107         text = buffer.strip()
108         # analyze first n characters
109         if len(text) > 0:
110             text = text.strip()
111             # it it looks like a json, then try to parse it
112             if text != "" and ((text[0] == "{") or (text[0] == "[")):
113                 try:
114                     json.loads(data.read())
115                     data.seek(0)
116                     return data, 'json', dialect
117                 except:
118                     data.seek(0)
119                     return data, None, dialect
120 
121         # lets try to figure out if its a csv
122         try:
123             data.seek(0)
124             first_few_lines = []
125             i = 0
126             for line in data:
127                 i += 1
128                 first_few_lines.append(line)
129                 if i > 0:
130                     break
131 
132             accepted_delimiters = [',','\t', ';']
133             dialect = csv.Sniffer().sniff(''.join(first_few_lines[0]), delimiters=accepted_delimiters)
134             data.seek(0)
135             # if csv dialect identified then return csv
136             if dialect:
137                 return data, 'csv', dialect
138             else:
139                 return data, None, dialect
140         except:
141             data.seek(0)
142             log.error('Could not detect format for this file')
143             log.error(traceback.format_exc())
144             # No file type identified
145             return data, None, dialect
146 
147 
148 
149 
150     def _setup(self,file, clean_rows = True, custom_parser = None):
151         """
152         Setup from file
153         :param file: fielpath or url
154         :param clean_rows:  if you want to clean rows for strange null values
155         :param custom_parser: if you want to parse the file with some custom parser
156         """
157 
158         col_map = {}
159         # get file data io, format and dialect
160         data, format, dialect = self._getDataIo(file)
161         data.seek(0) # make sure we are at 0 in file pointer
162 
163         if format is None:
164             log.error('Could not laod file into any format, supported formats are csv, json, xls, xslx')
165 
166         if custom_parser:
167             header, file_data = custom_parser(data, format)
168 
169         elif format == 'csv':
170             csv_reader = list(csv.reader(data, dialect))
171             header = csv_reader[0]
172             file_data =  csv_reader[1:]
173 
174         elif format in ['xlsx', 'xls']:
175             data.seek(0)
176             df = pandas.read_excel(data)
177             header = df.columns.values.tolist()
178             file_data = df.values.tolist()
179 
180         elif format == 'json':
181             data.seek(0)
182             json_doc = json.loads(data.read())
183             df = json_normalize(json_doc)
184             header = df.columns.values.tolist()
185             file_data = df.values.tolist()
186 
187         for col in header:
188             col_map[col] = col
189 
190         if clean_rows == True:
191             file_list_data = []
192             for row in file_data:
193                 row = self.cleanRow(row)
194                 file_list_data.append(row)
195         else:
196             file_list_data = file_data
197 
198         try:
199             return pandas.DataFrame(file_list_data, columns=header), col_map
200         except:
201             return pandas.read_csv(file), col_map
202
```
--- 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/mindsdb/libs/data_sources/file_ds.py b/mindsdb/libs/data_sources/file_ds.py
--- a/mindsdb/libs/data_sources/file_ds.py
+++ b/mindsdb/libs/data_sources/file_ds.py
@@ -124,8 +124,10 @@
             first_few_lines = []
             i = 0
             for line in data:
-                i += 1
+                if line in ['\r\n','\n']:
+                    continue
                 first_few_lines.append(line)
+                i += 1
                 if i > 0:
                     break

{"golden_diff": "diff --git a/mindsdb/libs/data_sources/file_ds.py b/mindsdb/libs/data_sources/file_ds.py\n--- a/mindsdb/libs/data_sources/file_ds.py\n+++ b/mindsdb/libs/data_sources/file_ds.py\n@@ -124,8 +124,10 @@\n             first_few_lines = []\n             i = 0\n             for line in data:\n-                i += 1\n+                if line in ['\\r\\n','\\n']:\n+                    continue\n                 first_few_lines.append(line)\n+                i += 1\n                 if i > 0:\n                     break\n", "issue": "Unbound local error\n**Your Environment**\r\nanaconda \r\n* Python version: 3.7.4\r\n* Pip version:19.2.2\r\n* Operating system:Windows\r\n* Python environment used (e.g. venv, conda): conda\r\n* Mindsdb version you tried to install:1.6.15\r\n* Additional info if applicable:\r\n\r\n**Describe the bug**\r\ngot Unbound local error while running this example \r\n[https://github.com/ZoranPandovski/mindsdb-examples/tree/master/air_quality](https://github.com/ZoranPandovski/mindsdb-examples/tree/master/air_quality)\r\n**To Reproduce**\r\nSteps to reproduce the behavior, for example:\r\n1. clone the repository\r\n2. Run that example code in a jupyter notebook and you should see the error as presented in the screenshot.\r\n\r\n**Expected behavior**\r\nIt should start the training.\r\n\r\n**Additional context**\r\n![1](https://user-images.githubusercontent.com/19743451/67293940-c7a91f00-f502-11e9-8601-eb8f98c914c4.PNG)\r\n![2](https://user-images.githubusercontent.com/19743451/67293955-cbd53c80-f502-11e9-91e6-108cc96e1061.PNG)\n", "before_files": [{"content": "import re\nfrom io import BytesIO, StringIO\nimport csv\nimport codecs\nimport json\nimport traceback\nimport codecs\n\nimport pandas\nfrom pandas.io.json import json_normalize\nimport requests\n\nfrom mindsdb.libs.data_types.data_source import DataSource\nfrom mindsdb.libs.data_types.mindsdb_logger import log\n\n\nclass FileDS(DataSource):\n\n    def cleanRow(self, row):\n        n_row = []\n        for cell in row:\n            if str(cell) in ['', ' ', '  ', 'NaN', 'nan', 'NA']:\n                cell = None\n            n_row.append(cell)\n\n        return n_row\n\n    def _getDataIo(self, file):\n        \"\"\"\n        This gets a file either url or local file and defiens what the format is as well as dialect\n        :param file: file path or url\n        :return: data_io, format, dialect\n        \"\"\"\n\n        ############\n        # get file as io object\n        ############\n\n        data = BytesIO()\n\n        # get data from either url or file load in memory\n        if file[:5] == 'http:' or file[:6] == 'https:':\n            r = requests.get(file, stream=True)\n            if r.status_code == 200:\n                for chunk in r:\n                    data.write(chunk)\n            data.seek(0)\n\n        # else read file from local file system\n        else:\n            try:\n                data = open(file, 'rb')\n            except Exception as e:\n                error = 'Could not load file, possible exception : {exception}'.format(exception = e)\n                log.error(error)\n                raise ValueError(error)\n\n\n        dialect = None\n\n        ############\n        # check for file type\n        ############\n\n        # try to guess if its an excel file\n        xlsx_sig = b'\\x50\\x4B\\x05\\06'\n        xlsx_sig2 = b'\\x50\\x4B\\x03\\x04'\n        xls_sig = b'\\x09\\x08\\x10\\x00\\x00\\x06\\x05\\x00'\n\n        # different whence, offset, size for different types\n        excel_meta = [ ('xls', 0, 512, 8), ('xlsx', 2, -22, 4)]\n\n        for filename, whence, offset, size in excel_meta:\n\n            try:\n                data.seek(offset, whence)  # Seek to the offset.\n                bytes = data.read(size)  # Capture the specified number of bytes.\n                data.seek(0)\n                codecs.getencoder('hex')(bytes)\n\n                if bytes == xls_sig:\n                    return data, 'xls', dialect\n                elif bytes == xlsx_sig:\n                    return data, 'xlsx', dialect\n\n            except:\n                data.seek(0)\n\n        # if not excel it can be a json file or a CSV, convert from binary to stringio\n\n        byte_str = data.read()\n        # Move it to StringIO\n        try:\n            # Handle Microsoft's BOM \"special\" UTF-8 encoding\n            if byte_str.startswith(codecs.BOM_UTF8):\n                data = StringIO(byte_str.decode('utf-8-sig'))\n            else:\n                data = StringIO(byte_str.decode('utf-8'))\n\n        except:\n            log.error(traceback.format_exc())\n            log.error('Could not load into string')\n\n        # see if its JSON\n        buffer = data.read(100)\n        data.seek(0)\n        text = buffer.strip()\n        # analyze first n characters\n        if len(text) > 0:\n            text = text.strip()\n            # it it looks like a json, then try to parse it\n            if text != \"\" and ((text[0] == \"{\") or (text[0] == \"[\")):\n                try:\n                    json.loads(data.read())\n                    data.seek(0)\n                    return data, 'json', dialect\n                except:\n                    data.seek(0)\n                    return data, None, dialect\n\n        # lets try to figure out if its a csv\n        try:\n            data.seek(0)\n            first_few_lines = []\n            i = 0\n            for line in data:\n                i += 1\n                first_few_lines.append(line)\n                if i > 0:\n                    break\n\n            accepted_delimiters = [',','\\t', ';']\n            dialect = csv.Sniffer().sniff(''.join(first_few_lines[0]), delimiters=accepted_delimiters)\n            data.seek(0)\n            # if csv dialect identified then return csv\n            if dialect:\n                return data, 'csv', dialect\n            else:\n                return data, None, dialect\n        except:\n            data.seek(0)\n            log.error('Could not detect format for this file')\n            log.error(traceback.format_exc())\n            # No file type identified\n            return data, None, dialect\n\n\n\n\n    def _setup(self,file, clean_rows = True, custom_parser = None):\n        \"\"\"\n        Setup from file\n        :param file: fielpath or url\n        :param clean_rows:  if you want to clean rows for strange null values\n        :param custom_parser: if you want to parse the file with some custom parser\n        \"\"\"\n\n        col_map = {}\n        # get file data io, format and dialect\n        data, format, dialect = self._getDataIo(file)\n        data.seek(0) # make sure we are at 0 in file pointer\n\n        if format is None:\n            log.error('Could not laod file into any format, supported formats are csv, json, xls, xslx')\n\n        if custom_parser:\n            header, file_data = custom_parser(data, format)\n\n        elif format == 'csv':\n            csv_reader = list(csv.reader(data, dialect))\n            header = csv_reader[0]\n            file_data =  csv_reader[1:]\n\n        elif format in ['xlsx', 'xls']:\n            data.seek(0)\n            df = pandas.read_excel(data)\n            header = df.columns.values.tolist()\n            file_data = df.values.tolist()\n\n        elif format == 'json':\n            data.seek(0)\n            json_doc = json.loads(data.read())\n            df = json_normalize(json_doc)\n            header = df.columns.values.tolist()\n            file_data = df.values.tolist()\n\n        for col in header:\n            col_map[col] = col\n\n        if clean_rows == True:\n            file_list_data = []\n            for row in file_data:\n                row = self.cleanRow(row)\n                file_list_data.append(row)\n        else:\n            file_list_data = file_data\n\n        try:\n            return pandas.DataFrame(file_list_data, columns=header), col_map\n        except:\n            return pandas.read_csv(file), col_map\n", "path": "mindsdb/libs/data_sources/file_ds.py"}], "after_files": [{"content": "import re\nfrom io import BytesIO, StringIO\nimport csv\nimport codecs\nimport json\nimport traceback\nimport codecs\n\nimport pandas\nfrom pandas.io.json import json_normalize\nimport requests\n\nfrom mindsdb.libs.data_types.data_source import DataSource\nfrom mindsdb.libs.data_types.mindsdb_logger import log\n\n\nclass FileDS(DataSource):\n\n    def cleanRow(self, row):\n        n_row = []\n        for cell in row:\n            if str(cell) in ['', ' ', '  ', 'NaN', 'nan', 'NA']:\n                cell = None\n            n_row.append(cell)\n\n        return n_row\n\n    def _getDataIo(self, file):\n        \"\"\"\n        This gets a file either url or local file and defiens what the format is as well as dialect\n        :param file: file path or url\n        :return: data_io, format, dialect\n        \"\"\"\n\n        ############\n        # get file as io object\n        ############\n\n        data = BytesIO()\n\n        # get data from either url or file load in memory\n        if file[:5] == 'http:' or file[:6] == 'https:':\n            r = requests.get(file, stream=True)\n            if r.status_code == 200:\n                for chunk in r:\n                    data.write(chunk)\n            data.seek(0)\n\n        # else read file from local file system\n        else:\n            try:\n                data = open(file, 'rb')\n            except Exception as e:\n                error = 'Could not load file, possible exception : {exception}'.format(exception = e)\n                log.error(error)\n                raise ValueError(error)\n\n\n        dialect = None\n\n        ############\n        # check for file type\n        ############\n\n        # try to guess if its an excel file\n        xlsx_sig = b'\\x50\\x4B\\x05\\06'\n        xlsx_sig2 = b'\\x50\\x4B\\x03\\x04'\n        xls_sig = b'\\x09\\x08\\x10\\x00\\x00\\x06\\x05\\x00'\n\n        # different whence, offset, size for different types\n        excel_meta = [ ('xls', 0, 512, 8), ('xlsx', 2, -22, 4)]\n\n        for filename, whence, offset, size in excel_meta:\n\n            try:\n                data.seek(offset, whence)  # Seek to the offset.\n                bytes = data.read(size)  # Capture the specified number of bytes.\n                data.seek(0)\n                codecs.getencoder('hex')(bytes)\n\n                if bytes == xls_sig:\n                    return data, 'xls', dialect\n                elif bytes == xlsx_sig:\n                    return data, 'xlsx', dialect\n\n            except:\n                data.seek(0)\n\n        # if not excel it can be a json file or a CSV, convert from binary to stringio\n\n        byte_str = data.read()\n        # Move it to StringIO\n        try:\n            # Handle Microsoft's BOM \"special\" UTF-8 encoding\n            if byte_str.startswith(codecs.BOM_UTF8):\n                data = StringIO(byte_str.decode('utf-8-sig'))\n            else:\n                data = StringIO(byte_str.decode('utf-8'))\n\n        except:\n            log.error(traceback.format_exc())\n            log.error('Could not load into string')\n\n        # see if its JSON\n        buffer = data.read(100)\n        data.seek(0)\n        text = buffer.strip()\n        # analyze first n characters\n        if len(text) > 0:\n            text = text.strip()\n            # it it looks like a json, then try to parse it\n            if text != \"\" and ((text[0] == \"{\") or (text[0] == \"[\")):\n                try:\n                    json.loads(data.read())\n                    data.seek(0)\n                    return data, 'json', dialect\n                except:\n                    data.seek(0)\n                    return data, None, dialect\n\n        # lets try to figure out if its a csv\n        try:\n            data.seek(0)\n            first_few_lines = []\n            i = 0\n            for line in data:\n                if line in ['\\r\\n','\\n']:\n                    continue\n                first_few_lines.append(line)\n                i += 1\n                if i > 0:\n                    break\n\n            accepted_delimiters = [',','\\t', ';']\n            dialect = csv.Sniffer().sniff(''.join(first_few_lines[0]), delimiters=accepted_delimiters)\n            data.seek(0)\n            # if csv dialect identified then return csv\n            if dialect:\n                return data, 'csv', dialect\n            else:\n                return data, None, dialect\n        except:\n            data.seek(0)\n            log.error('Could not detect format for this file')\n            log.error(traceback.format_exc())\n            # No file type identified\n            return data, None, dialect\n\n\n\n\n    def _setup(self,file, clean_rows = True, custom_parser = None):\n        \"\"\"\n        Setup from file\n        :param file: fielpath or url\n        :param clean_rows:  if you want to clean rows for strange null values\n        :param custom_parser: if you want to parse the file with some custom parser\n        \"\"\"\n\n        col_map = {}\n        # get file data io, format and dialect\n        data, format, dialect = self._getDataIo(file)\n        data.seek(0) # make sure we are at 0 in file pointer\n\n        if format is None:\n            log.error('Could not laod file into any format, supported formats are csv, json, xls, xslx')\n\n        if custom_parser:\n            header, file_data = custom_parser(data, format)\n\n        elif format == 'csv':\n            csv_reader = list(csv.reader(data, dialect))\n            header = csv_reader[0]\n            file_data =  csv_reader[1:]\n\n        elif format in ['xlsx', 'xls']:\n            data.seek(0)\n            df = pandas.read_excel(data)\n            header = df.columns.values.tolist()\n            file_data = df.values.tolist()\n\n        elif format == 'json':\n            data.seek(0)\n            json_doc = json.loads(data.read())\n            df = json_normalize(json_doc)\n            header = df.columns.values.tolist()\n            file_data = df.values.tolist()\n\n        for col in header:\n            col_map[col] = col\n\n        if clean_rows == True:\n            file_list_data = []\n            for row in file_data:\n                row = self.cleanRow(row)\n                file_list_data.append(row)\n        else:\n            file_list_data = file_data\n\n        try:\n            return pandas.DataFrame(file_list_data, columns=header), col_map\n        except:\n            return pandas.read_csv(file), col_map\n", "path": "mindsdb/libs/data_sources/file_ds.py"}]}