Skip to content

Commit 1b93bf0

Browse files
committed
update repr tests
1 parent 5b291d5 commit 1b93bf0

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

doc/source/whatsnew/v0.24.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ update the ``ExtensionDtype._metadata`` tuple to match the signature of your
858858
- :meth:`DataFrame.stack` no longer converts to object dtype for DataFrames where each column has the same extension dtype. The output Series will have the same dtype as the columns (:issue:`23077`).
859859
- :meth:`Series.unstack` and :meth:`DataFrame.unstack` no longer convert extension arrays to object-dtype ndarrays. Each column in the output ``DataFrame`` will now have the same dtype as the input (:issue:`23077`).
860860
- Bug when grouping :meth:`Dataframe.groupby()` and aggregating on ``ExtensionArray`` it was not returning the actual ``ExtensionArray`` dtype (:issue:`23227`).
861-
- A default repr for ExtensionArrays is now provided (:issue:`23601`).
861+
- A default repr for :class:`ExtensionArray` is now provided (:issue:`23601`).
862862

863863
.. _whatsnew_0240.api.incompatibilities:
864864

pandas/core/arrays/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ def __unicode__(self):
675675
# repr does. So we include a newline in our template, and strip
676676
# any trailing newlines from format_object_summary
677677
data = format_object_summary(self, self._formatter(), name=False,
678-
trailing_comma=False).rstrip('\n')
678+
trailing_comma=False).rstrip()
679679
name = self.__class__.__name__
680680
return template.format(class_name=name, data=data,
681681
length=len(self),

pandas/tests/arrays/test_integer.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,27 @@ def test_dtypes(dtype):
5757
assert dtype.name is not None
5858

5959

60-
def test_repr_array(data):
61-
result = repr(data)
62-
assert '<IntegerArray>' in result
63-
64-
# not long
65-
assert '...' not in result
66-
assert 'Length: ' in result
67-
assert 'dtype: ' in result
68-
69-
70-
def test_na_repr(data):
71-
result = repr(integer_array([1, None]))
72-
assert 'NaN' in result
73-
60+
def test_repr_array():
61+
result = repr(integer_array([1, None, 3]))
62+
expected = (
63+
'<IntegerArray>\n'
64+
'[1, NaN, 3]\n'
65+
'Length: 3, dtype: Int64'
66+
)
67+
assert result == expected
7468

75-
def test_repr_array_long(data):
76-
# some arrays may be able to assert a ... in the repr
77-
with pd.option_context('display.max_seq_items', 1):
78-
result = repr(data)
7969

80-
assert '...' in result
81-
assert 'Length' in result
70+
def test_repr_array_long():
71+
data = integer_array([1, 2, None] * 1000)
72+
expected = (
73+
"<IntegerArray>\n"
74+
"[ 1, 2, NaN, 1, 2, NaN, 1, 2, NaN, 1,\n"
75+
" ...\n"
76+
" NaN, 1, 2, NaN, 1, 2, NaN, 1, 2, NaN]\n"
77+
"Length: 3000, dtype: Int64"
78+
)
79+
result = repr(data)
80+
assert result == expected
8281

8382

8483
class TestConstructors(object):

0 commit comments

Comments
 (0)