andrewsu / mentorship-survey-analysis

MIT License
0 stars 0 forks source link

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

Closed andrewsu closed 1 year ago

andrewsu commented 1 year ago

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.

rjawesome commented 1 year ago

These errors are already caught -- I just have it printed to the console for debugging purposes on https://github.com/andrewsu/mentorship-survey-analysis/blob/65c39ac9171466e4671604c0b245a9a1f631b5bc/main.py#L190. This line can be commented out (which I will proabbly do soon) to prevent printing of this error.