Skip to content

Commit

Permalink
update repr tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Nov 11, 2018
1 parent 5b291d5 commit 1b93bf0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ update the ``ExtensionDtype._metadata`` tuple to match the signature of your
- :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`).
- :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`).
- Bug when grouping :meth:`Dataframe.groupby()` and aggregating on ``ExtensionArray`` it was not returning the actual ``ExtensionArray`` dtype (:issue:`23227`).
- A default repr for ExtensionArrays is now provided (:issue:`23601`).
- A default repr for :class:`ExtensionArray` is now provided (:issue:`23601`).

.. _whatsnew_0240.api.incompatibilities:

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def __unicode__(self):
# repr does. So we include a newline in our template, and strip
# any trailing newlines from format_object_summary
data = format_object_summary(self, self._formatter(), name=False,
trailing_comma=False).rstrip('\n')
trailing_comma=False).rstrip()
name = self.__class__.__name__
return template.format(class_name=name, data=data,
length=len(self),
Expand Down
39 changes: 19 additions & 20 deletions pandas/tests/arrays/test_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,27 @@ def test_dtypes(dtype):
assert dtype.name is not None


def test_repr_array(data):
result = repr(data)
assert '<IntegerArray>' in result

# not long
assert '...' not in result
assert 'Length: ' in result
assert 'dtype: ' in result


def test_na_repr(data):
result = repr(integer_array([1, None]))
assert 'NaN' in result

def test_repr_array():
result = repr(integer_array([1, None, 3]))
expected = (
'<IntegerArray>\n'
'[1, NaN, 3]\n'
'Length: 3, dtype: Int64'
)
assert result == expected

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

assert '...' in result
assert 'Length' in result
def test_repr_array_long():
data = integer_array([1, 2, None] * 1000)
expected = (
"<IntegerArray>\n"
"[ 1, 2, NaN, 1, 2, NaN, 1, 2, NaN, 1,\n"
" ...\n"
" NaN, 1, 2, NaN, 1, 2, NaN, 1, 2, NaN]\n"
"Length: 3000, dtype: Int64"
)
result = repr(data)
assert result == expected


class TestConstructors(object):
Expand Down

0 comments on commit 1b93bf0

Please sign in to comment.