Skip to content

Commit 2b5fe25

Browse files
committed
BUG: Fixed SparseArray formatter
We want to fall back to the implementation in formats.
1 parent ef390fc commit 2b5fe25

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

pandas/core/arrays/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ def __repr__(self):
676676
dtype=self.dtype)
677677

678678
def _formatter(self, boxed=False):
679-
# type: (bool) -> Callable[[Any], str]
679+
# type: (bool) -> Callable[[Any], Optional[str]]
680680
"""Formatting function for scalar values.
681681
682682
This is used in the default '__repr__'. The returned formatting

pandas/core/arrays/sparse.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1739,12 +1739,7 @@ def __unicode__(self):
17391739
index=printing.pprint_thing(self.sp_index))
17401740

17411741
def _formatter(self, boxed=False):
1742-
def fmt(x):
1743-
if isna(x) and isinstance(x, float):
1744-
return 'NaN'
1745-
return str(x)
1746-
1747-
return fmt
1742+
return None
17481743

17491744

17501745
SparseArray._add_arithmetic_ops()

pandas/io/formats/format.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1123,9 +1123,12 @@ class ExtensionArrayFormatter(GenericArrayFormatter):
11231123
def _format_strings(self):
11241124
values = self.values
11251125
if isinstance(values, (ABCIndexClass, ABCSeries)):
1126+
boxed = True
11261127
values = values._values
1128+
else:
1129+
boxed = False
11271130

1128-
formatter = values._formatter(self)
1131+
formatter = values._formatter(boxed=boxed)
11291132

11301133
if is_categorical_dtype(values.dtype):
11311134
# Categorical is special for now, so that we can preserve tzinfo

0 commit comments

Comments
 (0)