andrewsu / mentorship-survey-analysis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

graceful handling of the "no numeric data to plot" error

andrewsu opened this issue · comments

Right now, the script produces many errors like this:

Q64:Please reflect on your mentoring experience. How can the mentorship climate at Scripps Research be improved for mentors?
Traceback (most recent call last):
  File "/home/asu/Science/mentorship-survey-analysis/main.py", line 156, in plot_bar_charts
    plottable_df.plot.barh(stacked=True, ax=axes[i])
  File "/home/asu/env/mentorship-survey-analysis/lib/python3.10/site-packages/pandas/plotting/_core.py", line 1222, in barh
    return self(kind="barh", x=x, y=y, **kwargs)
  File "/home/asu/env/mentorship-survey-analysis/lib/python3.10/site-packages/pandas/plotting/_core.py", line 975, in __call__
    return plot_backend.plot(data, kind=kind, **kwargs)
  File "/home/asu/env/mentorship-survey-analysis/lib/python3.10/site-packages/pandas/plotting/_matplotlib/__init__.py", line 71, in plot
    plot_obj.generate()
  File "/home/asu/env/mentorship-survey-analysis/lib/python3.10/site-packages/pandas/plotting/_matplotlib/core.py", line 446, in generate
    self._compute_plot_data()
  File "/home/asu/env/mentorship-survey-analysis/lib/python3.10/site-packages/pandas/plotting/_matplotlib/core.py", line 632, in _compute_plot_data
    raise TypeError("no numeric data to plot")
TypeError: no numeric data to plot

no numeric data to plot

These are expected errors given the sample data file and they do not indicate anything is actually going wrong, but their appearance in the console output may confuse users who are not familiar with the reason. It would be nice to catch these errors more gracefully.

These errors are already caught -- I just have it printed to the console for debugging purposes on

print(traceback.format_exc())
. This line can be commented out (which I will proabbly do soon) to prevent printing of this error.