I have half a day streamlit experience and I have the following issue.
The first time the server runs everything looks good. But then, when I make a change and the watcher reloads the page, I get this error
- Streamlit version: (get it with `$ streamlit version`)
- Python version: (get it with `$ python --version`)
- Using Conda? PipEnv? PyEnv? Pex?
- OS version:
- Browser version:
Also, is warnings.py your own code? Could you try renaming that file to something else?
It seems that itâs a warning thrown by the scikit library. The question is, why is it handled differently by streamlit at first load and subsequent loads?
The streamlit library is doing some funny business with sys.modules
At some point âwarningsâ is getting deleted from sys.modules
This is the bottom of the stack trace for the same issue as OP
File "/home/matt/code/monash/autumn/env/lib/python3.6/site-packages/matplotlib/cbook/deprecation.py", line 407, in _suppress_matplotlib_deprecation_warning
with warnings.catch_warnings():File "/home/matt/code/monash/autumn/env/lib/python3.6/warnings.py", line 437, in __init__
self._module = sys.modules['warnings'] if module is None else module
Something in streamlit is deleting âwarningsâ from sys.modules
for wm in self._watched_modules.values():
if wm.module_name is not None and wm.module_name in sys.modules:
if wm.module_name != "warnings":
del sys.modules[wm.module_name]
Hi @randyzwitch. My fix is really a situation-specific hack that would not be acceptible in the Streamlit codebase since it does not cover all bases. I believe that more investigation of this issue will be required before implementing a fix. If itâs helpful I can move this discussion to a GitHub issue and describe my hacky fix. (and link to issue from here)
Thatâs fair. Moving this to an issue would be great, along with your hack, so that one of our engineers can evaluate why the line that you modified is there in the first place.
Pandas KeyError occurs when we try to access some column/row label in our DataFrame that doesnât exist. Usually, this error occurs when you misspell a column/row name or include an unwanted space before or after the column/row name⌠Before doing anything with the data frame, use print(df.columns) to see dataframe column exist or not.
print(df.columns)
I was getting a similar kind of error in one of my codes. Turns out, that particular index was missing from my data frame as I had dropped the empty dataframe 2 rows. If this is the case, you can do df.reset_index(inplace=True) and the error should be resolved.