-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
CLN: Make repeat method consistent #24395
Conversation
Hello @jschendel! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on December 23, 2018 at 21:02 Hours UTC |
|
||
Parameters | ||
---------- | ||
repeats : int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that repeat
can be an array of ints in the numpy implementation, and this appears to work for the pandas implementation as well. Added tests for this behavior in places it didn't previously exist.
In [2]: np.array([10, 20, 30]).repeat([1, 2, 3])
Out[2]: array([10, 20, 20, 30, 30, 30])
In [3]: pd.Index(list('abc')).repeat([1, 2, 3])
Out[3]: Index(['a', 'b', 'b', 'c', 'c', 'c'], dtype='object')
left_repeat = self.left.repeat(repeats, **kwargs) | ||
right_repeat = self.right.repeat(repeats, **kwargs) | ||
@Appender(_extension_array_shared_docs['repeat'] % _shared_docs_kwargs) | ||
def repeat(self, repeats, *args, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The base class implementation works for IntervalArray
as well, but a couple off-the-cuff timings had this implementation 1.5x - 2x faster.
@@ -292,22 +292,6 @@ def test_validate_inplace(self): | |||
with pytest.raises(ValueError): | |||
cat.sort_values(inplace=value) | |||
|
|||
def test_repeat(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleted as these appear to be testing the same thing as the base class tests in tests/extension/base/methods.py
@@ -26,22 +26,6 @@ def left_right_dtypes(request): | |||
|
|||
class TestMethods(object): | |||
|
|||
@pytest.mark.parametrize('repeats', [0, 1, 5]) | |||
def test_repeat(self, left_right_dtypes, repeats): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleted as these appear to be testing the same thing as the base class tests in tests/extension/base/methods.py
@@ -317,26 +317,6 @@ def test_shift(self): | |||
# This is tested in test_arithmetic | |||
pass | |||
|
|||
def test_repeat(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
condensed these into test_repeat_freqstr
in test_period.py
pd.period_range('2001-01-01', periods=3, freq='2D'), | ||
marks=pytest.mark.xfail(reason='GH 24391')), | ||
pd.PeriodIndex(['2001-01', 'NaT', '2003-01'], freq='M')]) | ||
def test_repeat_freqstr(self, index, use_numpy): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed so this doesn't override the base class tests, which test some additional things (array of ints, errors)
@@ -445,17 +451,6 @@ def test_pindex_qaccess(self): | |||
# Todo: fix these accessors! | |||
assert s['05Q4'] == s[2] | |||
|
|||
def test_numpy_repeat(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleted since this overrides the base class implementation and appears to be doing the same thing.
Codecov Report
@@ Coverage Diff @@
## master #24395 +/- ##
==========================================
+ Coverage 92.3% 92.3% +<.01%
==========================================
Files 162 162
Lines 51875 51872 -3
==========================================
- Hits 47883 47882 -1
+ Misses 3992 3990 -2
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #24395 +/- ##
==========================================
+ Coverage 92.3% 92.3% +<.01%
==========================================
Files 162 163 +1
Lines 51875 51943 +68
==========================================
+ Hits 47883 47946 +63
- Misses 3992 3997 +5
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. just some questions on the docs.
@@ -1038,12 +1038,61 @@ def _set_values(self, key, value): | |||
|
|||
def repeat(self, repeats, *args, **kwargs): | |||
""" | |||
Repeat elements of an Series. Refer to `numpy.ndarray.repeat` | |||
for more information about the `repeats` argument. | |||
Repeat elements of a Series. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any way to re-use the doc-string you defined for EA (meaning here and for Index), maybe make it even more generic and parametrize on the types? (ok that we are duplicating code, but the more can share the better).
cc @datapythonista
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had the same thought but was unsure how to do it in a clean way. I think you could split the docstring to reuse to everything but the See Also and Examples section, then separately define only those sections for EA/Index/Series. Seems a bit convoluted though; certainly interested to hear if there's a better way.
pandas/core/series.py
Outdated
2 c | ||
2 c | ||
dtype: object | ||
>>> s.repeat(3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you mean to have 2 very similar examples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was mimicking the existing documentation for Index.repeat
which follows the same pattern of examples. Agreed that the two are quite similar; changing the second example to be an array of ints example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is ok, just thinking if this can be made simpler.
thanks @jschendel can probably use the |
I think the signature should just be |
Follow-up to changes made in #24349. Basically trying to make the
repeat
method as consistent as possible across the various implementations within the codebase.Summary:
repeat(self, repeats, *args, **kwargs)
repeat(self, repeats, axis=None)
but I opted to match on the least restrictive function signature instead.cc @TomAugspurger