Skip to content

ENH: ExtensionArray.repeat #24349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 20, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
updates
  • Loading branch information
TomAugspurger committed Dec 19, 2018
commit a16c253de660e645f5855ca9ec423feb09bafdac
2 changes: 2 additions & 0 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ def repeat(self, repeats, axis=None):
"""
Repeat elements of an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a versionadded. Will do that on merge maybe, unless there are other comments on the implementation.

.. versionadded:: 0.24.0

Parameters
----------
repeats : int
Expand Down
14 changes: 11 additions & 3 deletions pandas/tests/extension/base/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,16 @@ def test_where_series(self, data, na_value, as_frame):
expected = expected.to_frame(name='a')
self.assert_equal(result, expected)

@pytest.mark.parametrize("as_series", [True, False])
@pytest.mark.parametrize("repeats", [0, 1, 2])
def test_repeat(self, data, repeats):
def test_repeat(self, data, repeats, as_series):
a, b, c = data[:3]
data = type(data)._from_sequence([a, b, c], dtype=data.dtype)
result = data.repeat(repeats)
arr = type(data)._from_sequence([a, b, c], dtype=data.dtype)

if as_series:
arr = pd.Series(arr)

result = arr.repeat(repeats)

if repeats == 0:
expected = []
Expand All @@ -278,6 +283,9 @@ def test_repeat(self, data, repeats):
else:
expected = [a, a, b, b, c, c]
expected = type(data)._from_sequence(expected, dtype=data.dtype)
if as_series:
index = pd.Series(np.arange(len(arr))).repeat(repeats).index
expected = pd.Series(expected, index=index)
self.assert_equal(result, expected)

def test_repeat_raises(self, data):
Expand Down