Mohitur669 / Olympic-Data-Analysis-WebApp

This is an Exploratory Data Analysis project to analyze the modern Olympic Games, including all the Games from Athens 1896 to Rio 2016.
https://olympic-analysis.streamlit.app/
1 stars 0 forks source link

Please fix the bug of heatmap plotting when there is no data #1

Closed Mohitur669 closed 1 year ago

Mohitur669 commented 1 year ago

Reproducing the Bug

  1. Run the app.py file through streamlit
  2. Select the "Country-wise Analysis" option
  3. In the "Select a Country" dropdown menu select "Andorra" or maybe "Angola" or maybe "Aruba". In short, the countries which have no data to put into the heatmap give the error mentioned below.

`ValueError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you're on Streamlit Cloud, click on 'Manage app' in the lower right of your app).

Traceback: File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script exec(code, module.dict) File "/app/olympic-data-analysis-webapp/app.py", line 127, in ax = sns.heatmap(pt, annot=True) File "/home/appuser/venv/lib/python3.9/site-packages/seaborn/matrix.py", line 446, in heatmap plotter = _HeatMapper(data, vmin, vmax, cmap, center, robust, annot, fmt, File "/home/appuser/venv/lib/python3.9/site-packages/seaborn/matrix.py", line 163, in init self._determine_cmap_params(plot_data, vmin, vmax, File "/home/appuser/venv/lib/python3.9/site-packages/seaborn/matrix.py", line 202, in _determine_cmap_params vmin = np.nanmin(calc_data) File "<__array_function__ internals>", line 200, in nanmin File "/home/appuser/venv/lib/python3.9/site-packages/numpy/lib/nanfunctions.py", line 343, in nanmin res = np.fmin.reduce(a, axis=axis, out=out, **kwargs)`

Please fix the bug as soon as possible.

Mohitur669 commented 1 year ago

replacing the below lines:

fig, ax = plt.subplots(figsize=(20, 20)) ax = sns.heatmap(pt, annot=True) st.pyplot(fig)

for case pt is empty or contains null values, we need to try: if pt is None or pt.empty:st.write("No data available for selected country.") else:   # Heatmap plot   fig, ax = plt.subplots(figsize=(20, 20))   ax = sns.heatmap(pt, annot=True)   st.pyplot(fig)

This will fix the bug.