Skip to content

Commit 193747e

Browse files
committed
update docs, type
1 parent 6e64b7b commit 193747e

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

pandas/core/arrays/base.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -681,17 +681,25 @@ def __repr__(self):
681681
dtype=self.dtype)
682682

683683
def _formatter(self, formatter=None):
684-
# type: (ExtensionArrayFormatter) -> Callable[Any]
684+
# type: (Optional[ExtensionArrayFormatter]) -> Callable[[Any], str]
685685
"""Formatting function for scalar values.
686686
687687
This is used in the default '__repr__'. The formatting function
688688
receives instances of your scalar type.
689689
690690
Parameters
691691
----------
692-
boxed: bool, default False
693-
Whether the formatter is to be used by pandas inside a Series
694-
or DataFrame repr.
692+
formatter: GenericArrayFormatter, optional
693+
The formatter this array is being rendered with. The formatter
694+
may have a `.formatter` method already defined. By default, this
695+
will be used if a `formatter` is passed, otherwise the formatter
696+
is ``str``.
697+
698+
Returns
699+
-------
700+
Callable[[Any], str]
701+
A callable that gets instances of the scalar type and
702+
returns a string.
695703
"""
696704
return getattr(formatter, 'formatter', None) or str
697705

pandas/core/arrays/integer.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,14 @@ def _from_sequence(cls, scalars, dtype=None, copy=False):
264264
def _from_factorized(cls, values, original):
265265
return integer_array(values, dtype=original.dtype)
266266

267-
def _formatter(self, boxed=False):
268-
def fmt(x):
269-
if isna(x):
270-
return 'NaN'
271-
return str(x)
272-
return fmt
267+
def _formatter(self, formatter=None):
268+
if formatter is None:
269+
def fmt(x):
270+
if isna(x):
271+
return 'NaN'
272+
return str(x)
273+
return fmt
274+
return formatter.formatter
273275

274276
def __getitem__(self, item):
275277
if is_integer(item):

pandas/core/arrays/period.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ def start_time(self):
330330
def end_time(self):
331331
return self.to_timestamp(how='end')
332332

333-
def _formatter(self, boxed=False):
334-
if boxed:
333+
def _formatter(self, formatter=None):
334+
if formatter:
335335
return str
336336
return "'{}'".format
337337

pandas/tests/arrays/test_integer.py

+5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ def test_repr_array(data):
6767
assert 'dtype: ' in result
6868

6969

70+
def test_na_repr(data):
71+
result = repr(integer_array([1, None]))
72+
assert 'NaN' in result
73+
74+
7075
def test_repr_array_long(data):
7176
# some arrays may be able to assert a ... in the repr
7277
with pd.option_context('display.max_seq_items', 1):

0 commit comments

Comments
 (0)