Skip to content
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

added negative value support in pct_changes of generic.py #56627

Closed

Conversation

paridhisharma24
Copy link

closes #56618

@asishm-wk
Copy link

Thanks for the PR. Few points:

  1. We can't change the default behavior without a deprecation cycle here (and reading the comments of the issue, don't think the default needs to change either).
  2. You'll need to add another argument/parameter to the pct_change method that indicates whether or not you want to take absolute value of the denominator (similar changes would be required in your tests as well)

@paridhisharma24
Copy link
Author

@asishm-wk I am not able to figure out the issue with the failing check
Could you please help with the same

@asishm
Copy link
Contributor

asishm commented Dec 28, 2023

The error comes from mypy - if you click on the failed build.

pandas/core/generic.py:12152: error: Unsupported left operand type for / ("Self") [operator]
pandas/core/generic.py:12152: note: Right operand is of type "Self | DataFrame"

Looks like you removed the type ignore comment when you made the changes (needs to be there in both the if and else statements).

Copy link
Contributor

@asishm asishm left a comment

Choose a reason for hiding this comment

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

tests should likely go in pandas/tests/series/methods/test_pct_change.py and see if you can use an existing test and parametrize the new argument.

@@ -12145,7 +12146,10 @@ def pct_change(

shifted = data.shift(periods=periods, freq=freq, axis=axis, **kwargs)
# Unsupported left operand type for / ("Self")
rs = data / shifted - 1 # type: ignore[operator]
if use_absolute_value:
rs = rs = (data - shifted) / abs(shifted) # type: ignore[operator]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
rs = rs = (data - shifted) / abs(shifted) # type: ignore[operator]
rs = (data - shifted) / abs(shifted) # type: ignore[operator]

@@ -1,3 +1,4 @@
import random
Copy link
Contributor

Choose a reason for hiding this comment

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

is the import and setting the seed below required?

Copy link
Author

Choose a reason for hiding this comment

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

will check and remove if not required

@WillAyd
Copy link
Member

WillAyd commented Jan 2, 2024

I appreciate the PR but I am not sure it is worth expanding the API for this.

@mroeschke
Copy link
Member

Thanks for the PR but it is a bit too early to craft a solution to the issue as it's still being actively discussed. Going to close but we can reopen if it has more acceptance from the core developers

@mroeschke mroeschke closed this Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Add option to use absolute value in pct_change
5 participants