gyli / PyWaffle

🧇 Make Waffle Charts in Python.
MIT License
578 stars 105 forks source link

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). #5

Closed ghost closed 6 years ago

ghost commented 6 years ago

When using a pandas DataFrame, I keep getting this error, no matter what DataFrame I use:

Traceback (most recent call last):
  File "clean_input_file.py", line 177, in <module>
    main()
  File "clean_input_file.py", line 172, in main
    plot_res(data_FSW)
  File "clean_input_file.py", line 149, in plot_res
    title={'label': 'Vote Percentage in 2016 US Presidential Election', 'loc': 'left'}
  File "C:\Users\Pez Amaury\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\pyplot.py", line 548, in figure
    **kwargs)
  File "C:\Users\Pez Amaury\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\backend_bases.py", line 160, in new_figure_manager
    fig = fig_cls(*args, **kwargs)
  File "C:\Users\Pez Amaury\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pywaffle\waffle.py", line 158, in __init__
    if (not self.fig_args['values'] or not self.fig_args['rows']) and not self.plots:
  File "C:\Users\Pez Amaury\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\generic.py", line 1573, in __nonzero__
    .format(self.__class__.__name__))
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

I understand this is due to using operators or/and in waffle.py, so changing them to np.logical_and and np.logical_or would probably solve the problem.

Here's the dataFrame I'm using:

Variables ART last 12 months 0.0 Access to condoms last 12 months 0.0 Any STI treatment last 12 months 0.0 Clean needles/syringes at last injection 0.0 Condom use at last time they had sex 0.0 Condom use when had anal sex last time with a male partner 0.0 Condom use when had sex last time with a commercial client 0.0 HBV Prevalence 0.0 HCV Prevalence 0.0 HIV Prevalence 0.0 HIV incidence 0.0 HIV test history 0.0 HIV test in last 12 months 0.0 HIV-1 Prevalence 0.0 HIV-2 Prevalence 0.0 OST/MMT last 6 months 0.0 Other STI Prevalence 0.0 Received HIV test results 0.0 STI test last 12 months 0.0 Syphilis Prevalence 0.0 Name: 2001, dtype: float64

gyli commented 6 years ago

Thank you for letting me know this issue!

I have figured out what causes this issue and I will fix it soon.

At current stage, if you want to avoid this error with current version, you can either use parameter "plots" with "111" as the position for the single plot, or convert the pandas series into list or dict.

gyli commented 6 years ago

Fixed. Please upgrade to the latest version 0.0.9.

ghost commented 6 years ago

Thank you :)