Skip to content

Commit db2d16a

Browse files
simonjayhawkinsjreback
authored andcommitted
BUG: Series/DataFrame with IntervalIndex doesn't display NaN in index (#25993)
1 parent 1322eb0 commit db2d16a

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

doc/source/whatsnew/v0.25.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ Interval
318318
^^^^^^^^
319319

320320
- Construction of :class:`Interval` is restricted to numeric, :class:`Timestamp` and :class:`Timedelta` endpoints (:issue:`23013`)
321-
-
321+
- Fixed bug in :class:`Series`/:class:`DataFrame` not displaying ``NaN`` in :class:`IntervalIndex` with missing values (:issue:`25984`)
322322
-
323323

324324
Indexing

pandas/core/indexes/interval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ def __getitem__(self, value):
10151015
def _format_with_header(self, header, **kwargs):
10161016
return header + list(self._format_native_types(**kwargs))
10171017

1018-
def _format_native_types(self, na_rep='', quoting=None, **kwargs):
1018+
def _format_native_types(self, na_rep='NaN', quoting=None, **kwargs):
10191019
""" actually format my specific types """
10201020
from pandas.io.formats.format import ExtensionArrayFormatter
10211021
return ExtensionArrayFormatter(values=self,

pandas/tests/indexes/interval/test_interval.py

+17
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,23 @@ def test_frame_repr(self):
378378
)
379379
assert result == expected
380380

381+
@pytest.mark.parametrize('constructor,expected', [
382+
(pd.Series, ('(0.0, 1.0] a\n'
383+
'NaN b\n'
384+
'(2.0, 3.0] c\n'
385+
'dtype: object')),
386+
(pd.DataFrame, (' 0\n'
387+
'(0.0, 1.0] a\n'
388+
'NaN b\n'
389+
'(2.0, 3.0] c'))
390+
])
391+
def test_repr_missing(self, constructor, expected):
392+
# GH 25984
393+
index = IntervalIndex.from_tuples([(0, 1), np.nan, (2, 3)])
394+
obj = constructor(list('abc'), index=index)
395+
result = repr(obj)
396+
assert result == expected
397+
381398
# TODO: check this behavior is consistent with test_interval_new.py
382399
def test_get_item(self, closed):
383400
i = IntervalIndex.from_arrays((0, 1, np.nan), (1, 2, np.nan),

0 commit comments

Comments
 (0)