Skip to content

Commit

Permalink
Sparse formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Jan 30, 2018
1 parent df18c3b commit ab2f045
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
is_integer,
is_float,
is_scalar,
is_sparse,
is_numeric_dtype,
is_datetime64_dtype,
is_timedelta64_dtype,
Expand Down Expand Up @@ -1803,6 +1804,8 @@ def format_array(values, formatter, float_format=None, na_rep='NaN',
fmt_klass = CategoricalArrayFormatter
elif is_interval_dtype(values):
fmt_klass = IntervalArrayFormatter
elif is_sparse(values):
fmt_klass = SparseArrayFormatter
elif is_float_dtype(values.dtype):
fmt_klass = FloatArrayFormatter
elif is_period_arraylike(values):
Expand Down Expand Up @@ -2115,6 +2118,15 @@ def _format_strings(self):
return fmt_values


class SparseArrayFormatter(GenericArrayFormatter):

def _format_strings(self):
return format_array(self.values.get_values(), self.formatter,
float_format=self.float_format,
na_rep=self.na_rep, digits=self.digits,
space=self.space, justify=self.justify)


def format_percentiles(percentiles):
"""
Outputs rounded and formatted percentiles.
Expand Down

0 comments on commit ab2f045

Please sign in to comment.