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

[#7292] BUG: asfreq / pct_change strange behavior #19410

Merged
merged 13 commits into from
Jan 31, 2018

Conversation

minggli
Copy link
Contributor

@minggli minggli commented Jan 26, 2018

@jreback
Copy link
Contributor

jreback commented Jan 26, 2018

can u add tests from the original issue

@minggli
Copy link
Contributor Author

minggli commented Jan 26, 2018

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?

@jreback
Copy link
Contributor

jreback commented Jan 26, 2018

the idea is that the original should fail w/o your fix and pass with it

@codecov
Copy link

codecov bot commented Jan 26, 2018

Codecov Report

Merging #19410 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 89.99% <100%> (-0.01%) ⬇️
#single 41.74% <0%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/generic.py 95.91% <100%> (ø) ⬆️
pandas/core/indexes/multi.py 95.14% <0%> (-1.09%) ⬇️
pandas/core/sparse/array.py 91.48% <0%> (-0.34%) ⬇️
pandas/core/frame.py 97.57% <0%> (-0.05%) ⬇️
pandas/core/sparse/series.py 95.26% <0%> (-0.04%) ⬇️
pandas/core/indexes/numeric.py 97.24% <0%> (-0.04%) ⬇️
pandas/core/indexes/timedeltas.py 90.56% <0%> (-0.02%) ⬇️
pandas/core/indexes/interval.py 92.39% <0%> (-0.02%) ⬇️
pandas/core/indexes/period.py 92.99% <0%> (-0.02%) ⬇️
pandas/core/indexes/base.py 96.45% <0%> (-0.01%) ⬇️
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8a7aca9...75b8942. Read the comment docs.

@minggli
Copy link
Contributor Author

minggli commented Jan 26, 2018

added test cases (frame and series) against original issue raised. @jreback

@@ -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`)
Copy link
Contributor

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.

Copy link
Contributor Author

@minggli minggli Jan 26, 2018

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

@minggli
Copy link
Contributor Author

minggli commented Jan 26, 2018

@jreback @TomAugspurger let me know if this is good to go, otherwise have a good weekend. :)

@jreback jreback added Datetime Datetime data dtype Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Jan 27, 2018
@@ -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)
Copy link
Contributor

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):
Copy link
Contributor

Choose a reason for hiding this comment

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

same comments as above

Copy link
Contributor Author

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.

@minggli minggli closed this Jan 27, 2018
@minggli minggli reopened this Jan 27, 2018
@minggli minggli closed this Jan 28, 2018
@minggli minggli reopened this Jan 28, 2018
@minggli minggli closed this Jan 29, 2018
@minggli minggli reopened this Jan 29, 2018
@minggli
Copy link
Contributor Author

minggli commented Jan 30, 2018

@jreback @TomAugspurger is this good to go?

Copy link
Contributor

@TomAugspurger TomAugspurger left a 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 = \
Copy link
Contributor

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)

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -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`)
Copy link
Contributor

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"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

corrected.

@minggli
Copy link
Contributor Author

minggli commented Jan 31, 2018

@TomAugspurger reviews actioned.

@jreback jreback added this to the 0.23.0 milestone Jan 31, 2018
@jreback jreback merged commit 1bd7b3a into pandas-dev:master Jan 31, 2018
@jreback
Copy link
Contributor

jreback commented Jan 31, 2018

thanks @minggli

@minggli minggli deleted the bugfixs/7292 branch January 31, 2018 11:36
@minggli
Copy link
Contributor Author

minggli commented Jan 31, 2018

happy to contribute! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants