-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ExtensionArray.shift incorrect for periods larger than length of array #23911
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
Comments
Hi, I would like to try and tackle this issue to bite my teeth into the pandas codebase, however I'm not entirely sure about the expected behaviour of the shift method. From what I understand, when shift is called, the first period elements (up to the array's len) become NaN, and if period is smaller than the len of the array the original len-period elements become the last len-period elements, respecting the condition that period+len-period == len of the original array. Is this correct? |
@Devilmoon thanks. I think your summary is correct. The implementation is correct when The issue is on pandas/pandas/core/arrays/base.py Line 454 in a7b187a
That should be empty = self._from_sequence(
[self.dtype.na_value] * min(abs(periods), len(self)),
dtype=self.dtype
) |
@TomAugspurger I'm trying to grok the correct way to put in a test for this. I want to understand why a new base test is required under |
We write base tests for things that should be true of all extension array implementations http://pandas-docs.github.io/pandas-docs-travis/extending.html#testing-extension-arrays I think something like def test_shift_large_periods(self, data, na_value):
data = data[:5]
result = data.shift(10)
expected = type(data)._construct_from_sequence([na_value] * 10)
self.assert_extension_array_equal(result, expected) should work, but I haven't tested it. Maybe also test for |
Understood. Different question, why then should it be in that particular file which contains tests under the |
It could also go under the interface tests.
…On Mon, Nov 26, 2018 at 11:42 AM Varad Gunjal ***@***.***> wrote:
Understood. Different question, why then should it be in that particular
file which contains tests under the BaseMethodsTest class that are meant
for Series and DataFrame methods?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#23911 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABQHItGGYotleCMFBKt-a9pEH6lYpgSWks5uzCgcgaJpZM4YyCb_>
.
|
I followed a slightly different approach for the tests in the PR. Please let me know if that works. |
* Fixing shift() for ExtensionArray #23911
* Fixing shift() for ExtensionArray pandas-dev#23911
* Fixing shift() for ExtensionArray pandas-dev#23911
The expected output is
similar to categorical
This will need a new base test in
tests/extension/base/methods.py
and a fix inpandas/pandas/core/arrays/base.py
Line 430 in a7b187a
The text was updated successfully, but these errors were encountered: