-
Notifications
You must be signed in to change notification settings - Fork 117
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
Feat: Series.shift
Pyarrow Backend Implementation
#590
Conversation
for more information, see https://pre-commit.ci
β¦from_test_common
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
β¦from_test_common
β¦from_test_common
for more information, see https://pre-commit.ci
β¦from_test_common
β¦com/mfonekpo/narwhals into factor_out_testing_from_test_common
for more information, see https://pre-commit.ci
β¦from_test_common
for more information, see https://pre-commit.ci
β¦narwhals into Feat_Series_drop_nulls
Alright then.
β¦On Thu, 25 Jul 2024, 06:26 Francesco Bruzzesi, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In narwhals/_arrow/series.py
<#590 (comment)>
:
> + def shift(self, n: int) -> Self:
+ pc = get_pyarrow_compute()
+ return self._from_native_series(pc.shift(self._native_series, n))
This might end up being not so straightforward after all. We should
*manually* slice the original array and build the new one, this will also
be dependent on the sign of n
β
Reply to this email directly, view it on GitHub
<#590 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOA4GJDXMJF737IFUBBU7QTZOCEA7AVCNFSM6AAAAABLKD7LZSVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDCOJYGMZTSOJUGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
There is room for growth, right? Thank you. Is it ok? because you said it
is out of interest. What do I do?
β¦On Sun, Jul 28, 2024 at 2:09β―PM Marco Edward Gorelli < ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In narwhals/_arrow/series.py
<#590 (comment)>
:
> + # This condition shifts the series by n positions.
+ if n > 0:
+ # If n is positive, prepend nulls and truncate the end
+ shifted_chunks = [pa.array([None] * n, type=dtype)] + [
+ chunk.slice(0, len(chunk) - n) for chunk in chunks
+ ]
+ elif n < 0:
+ # If n is negative, append nulls and truncate the start
+ shifted_chunks = [chunk.slice(-n, len(chunk) + n) for chunk in chunks] + [
+ pa.array([None] * -n, type=dtype)
+ ]
+ else:
+ # If n is 0, return the original series
+ shifted_chunks = chunks
cool, thanks - I'm just a bit surprised, as it looks a bit more advanced
than other work you've submitted. if you figured this all out, then well
done π
β
Reply to this email directly, view it on GitHub
<#590 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOA4GJGVBBK57PHKQ75XC43ZOTUQXAVCNFSM6AAAAABLKD7LZSVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDEMBTGQ4DKOBYGE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
yup, definitely room for growth :) it's OK, if you add the test I suggested and it passes, then it should be fine |
Thanks, I will!
β¦On Sun, Jul 28, 2024 at 2:56β―PM Marco Edward Gorelli < ***@***.***> wrote:
yup, definitely room for growth :) it's OK, if you add the test I
suggested and it passes, then it should be fine
β
Reply to this email directly, view it on GitHub
<#590 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOA4GJGEKAN6PIUI3FGRY3DZOT2AZAVCNFSM6AAAAABLKD7LZSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENJUGUZDOOJWGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
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.
thanks for updating π ! have left a few comments
In general, I'd suggest that before asking for a review, you click on "files changed" and look through your changes yourself - it happens quite often that extra changes end up there which shouldn't be there. This fine is fine whilst learning π€ I'm just pointing it out so you know how to improve
tests/expr_and_series/shift_test.py
Outdated
def test_shift(constructor_eager: Any) -> None: | ||
df = nw.from_native(constructor_eager(data), eager_only=True) |
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.
these don't need to change in this test - only in test_shift_series
did you need to do that, constructor
is fine here, because we're testing Expr.shift
def test_shift(constructor_eager: Any) -> None: | |
df = nw.from_native(constructor_eager(data), eager_only=True) | |
def test_shift(constructor: Any) -> None: | |
df = nw.from_native(constructor(data)) |
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.
could you address this comment please?
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 still needs addressing, could you read over the suggested change more carefully and address it please?
You've removed the eager_only
part, but you still need to rename constructor_eager
to constructor
(just for this test!)
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.
I've added a commit to get this through
A bit of general feedback:
- in tests, you should construct
expected
explicitly, without any logic. The test case I handed you was like this, there was no need to modify it - the implementation for
shift
wasn't quite right. I'd pointed you to the solution (https://stackoverflow.com/a/78805975/4451315), why not try to just use that?
Anyway, thanks for your work here πͺ let's ship it
Thank you Marco, I have taken note of the points you listed. should I
refactor it to meet the standard?
β¦On Wed, Aug 7, 2024 at 2:45β―PM Marco Edward Gorelli < ***@***.***> wrote:
***@***.**** approved this pull request.
I've added a commit to get this through
A bit of general feedback:
- in tests, you should construct expected explicitly, without any
logic. The test case I handed you was like this, there was no need to
modify it
- the implementation for shift wasn't quite right. I'd pointed you to
the solution (https://stackoverflow.com/a/78805975/4451315), why not
try to just use that?
Anyway, thanks for your work here πͺ let's ship it
<https://camo.githubusercontent.com/1b87ba81f294957cce02b6ad5cb2ab324f25046e1c706c96323f544aa20f81a4/68747470733a2f2f692e666c756666792e63632f716b4e667050306a325074647439764458327171334e435871646b634b3673532e676966>
β
Reply to this email directly, view it on GitHub
<#590 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOA4GJHV7XXD6FB2ZXONB7LZQIQH3AVCNFSM6AAAAABLKD7LZSVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDEMRVGE3TMMBVGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
What type of PR is this? (check all applicable)
Related issues
Checklist
If you have comments or can explain your changes, please do so below.