Skip to content

Commit ab2f045

Browse files
committed
Sparse formatter
1 parent df18c3b commit ab2f045

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pandas/io/formats/format.py

+12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
is_integer,
2222
is_float,
2323
is_scalar,
24+
is_sparse,
2425
is_numeric_dtype,
2526
is_datetime64_dtype,
2627
is_timedelta64_dtype,
@@ -1803,6 +1804,8 @@ def format_array(values, formatter, float_format=None, na_rep='NaN',
18031804
fmt_klass = CategoricalArrayFormatter
18041805
elif is_interval_dtype(values):
18051806
fmt_klass = IntervalArrayFormatter
1807+
elif is_sparse(values):
1808+
fmt_klass = SparseArrayFormatter
18061809
elif is_float_dtype(values.dtype):
18071810
fmt_klass = FloatArrayFormatter
18081811
elif is_period_arraylike(values):
@@ -2115,6 +2118,15 @@ def _format_strings(self):
21152118
return fmt_values
21162119

21172120

2121+
class SparseArrayFormatter(GenericArrayFormatter):
2122+
2123+
def _format_strings(self):
2124+
return format_array(self.values.get_values(), self.formatter,
2125+
float_format=self.float_format,
2126+
na_rep=self.na_rep, digits=self.digits,
2127+
space=self.space, justify=self.justify)
2128+
2129+
21182130
def format_percentiles(percentiles):
21192131
"""
21202132
Outputs rounded and formatted percentiles.

0 commit comments

Comments
 (0)