HHammond / PrettyPandas

A Pandas Styler class for making beautiful tables
http://prettypandas.readthedocs.org/
MIT License
415 stars 23 forks source link

precision does not work for percentage format #38

Closed ghost closed 6 years ago

ghost commented 8 years ago

The as_percent() format always display the value without decimals and the precision parameter has no effect at all. I checked the code and realized that: 1/ there are 2 as_percent() in formatters (only 'partial' object is used) 2/ the method as_percent() in class PrettyPandas does not use the precision parameter at all, so I changed the call to partial below the comment: '# TODO: Find good way to implement precision' as:

    # TODO: Find good way to implement precision
    precision = self.precision if precision is None else precision

    add_formatter = partial(self._format_cells,
                            as_percent,
                            subset=subset,
                            format='0.{}%'.format('0' * precision))

maybe there is a better implementation but at least the precision is taken into account now.

HHammond commented 6 years ago

Thanks for the input, This will be fixed in 0.0.4 https://github.com/HHammond/PrettyPandas/pull/48

Sorry for the delay.