-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
[#7292] BUG: asfreq / pct_change strange behavior #19410
Conversation
can u add tests from the original issue |
Hi Jeff, can you clarify above comment? Do you mean assert pct_change(periods=5) == pct_change(periods=1, freq='5H'), as raised in the original issue? |
the idea is that the original should fail w/o your fix and pass with it |
Codecov Report
@@ Coverage Diff @@
## master #19410 +/- ##
==========================================
- Coverage 91.62% 91.62% -0.01%
==========================================
Files 150 150
Lines 48729 48725 -4
==========================================
- Hits 44649 44645 -4
Misses 4080 4080
Continue to review full report at Codecov.
|
added test cases (frame and series) against original issue raised. @jreback |
doc/source/whatsnew/v0.23.0.txt
Outdated
@@ -419,6 +419,7 @@ Datetimelike | |||
- Bug in ``.astype()`` to non-ns timedelta units would hold the incorrect dtype (:issue:`19176`, :issue:`19223`, :issue:`12425`) | |||
- Bug in subtracting :class:`Series` from ``NaT`` incorrectly returning ``NaT`` (:issue:`19158`) | |||
- Bug in :func:`Series.truncate` which raises ``TypeError`` with a monotonic ``PeriodIndex`` (:issue:`17717`) | |||
- Bug in :func:`NDFrame.pct_change` produces inconsistent frames using ``periods`` and ``freq`` (:issue:`7292`) |
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 link to NDFrame
won't work since it isn't in our API pages. Try
:func:`~DataFrame.pct_change`
It's also not clear (to me) what "inconsistent frames" means here.
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.
added change in new commit. @TomAugspurger
@jreback @TomAugspurger let me know if this is good to go, otherwise have a good weekend. :) |
@@ -120,6 +122,11 @@ def test_pct_change_shift_over_nas(self): | |||
edf = DataFrame({'a': expected, 'b': expected}) | |||
assert_frame_equal(chg, edf) | |||
|
|||
def test_pct_change_periods_freq(self): | |||
rs_periods = self.tsframe.pct_change(5) |
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.
add the issue number as a comment. Can you add a few more test cases here (via parametrization if possible). include an empty frame
@@ -353,6 +355,11 @@ def test_pct_change_shift_over_nas(self): | |||
expected = Series([np.nan, 0.5, np.nan, 2.5 / 1.5 - 1, .2]) | |||
assert_series_equal(chg, expected) | |||
|
|||
def test_pct_change_periods_freq(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.
same comments as above
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.
added additional test cases and test when frame is empty.
@jreback @TomAugspurger is this good to go? |
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.
Just a few style comments. Otherwise looks good.
rs_periods = self.tsframe.pct_change(3, fill_method='bfill') | ||
assert_frame_equal(rs_freq, rs_periods) | ||
|
||
rs_freq = \ |
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.
We try to avoid \
for line continuation in pandas. We use parenthesis instead. (same comment for lines 144 and 149)
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.
make sense :) thanks
@@ -120,6 +122,36 @@ def test_pct_change_shift_over_nas(self): | |||
edf = DataFrame({'a': expected, 'b': expected}) | |||
assert_frame_equal(chg, edf) | |||
|
|||
def test_pct_change_periods_freq(self): | |||
# see issue #7292 |
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.
Usually this is just # GH 7292
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.
done
doc/source/whatsnew/v0.23.0.txt
Outdated
@@ -419,6 +419,7 @@ Datetimelike | |||
- Bug in ``.astype()`` to non-ns timedelta units would hold the incorrect dtype (:issue:`19176`, :issue:`19223`, :issue:`12425`) | |||
- Bug in subtracting :class:`Series` from ``NaT`` incorrectly returning ``NaT`` (:issue:`19158`) | |||
- Bug in :func:`Series.truncate` which raises ``TypeError`` with a monotonic ``PeriodIndex`` (:issue:`17717`) | |||
- Bug in :func:`~DataFrame.pct_change` using ``periods`` and ``freq`` produces different sizes frames/series (:issue:`7292`) |
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.
Change "produces different sizes frames/series" to "returned different length outputs"
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.
corrected.
@TomAugspurger reviews actioned. |
thanks @minggli |
happy to contribute! 🚀 |
git diff upstream/master -u -- "*.py" | flake8 --diff