-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Series pct_change fill_method behavior #25291
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
Conversation
Hello @albertvillanova! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2019-08-30 16:38:20 UTC |
Codecov Report
@@ Coverage Diff @@
## master #25291 +/- ##
===========================================
- Coverage 91.72% 41.71% -50.01%
===========================================
Files 173 173
Lines 52831 52841 +10
===========================================
- Hits 48457 22045 -26412
- Misses 4374 30796 +26422
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #25291 +/- ##
=========================================
Coverage ? 91.68%
=========================================
Files ? 174
Lines ? 50751
Branches ? 0
=========================================
Hits ? 46531
Misses ? 4220
Partials ? 0
Continue to review full report at Codecov.
|
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.
haven't actually looked at the changes, rather some stylistic concerns
@jreback all checks have passed. |
@WillAyd @jschendel could you please have a look? |
pandas/core/generic.py
Outdated
raise ValueError("cannot pass both skipna and limit") | ||
if skipna is None and fill_method is None and limit is None: | ||
skipna = True | ||
if skipna and self._typ == 'dataframe': |
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.
use isinstance 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.
Hmm maybe add this to the frame subclass instead? Somewhat confusing to introspect here in the shared one.
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.
For the moment, I have added isinstance
as required by @jreback. Tell me if you both think I should do otherwise.
pandas/tests/generic/test_generic.py
Outdated
]) | ||
def test_pct_change_skipna_raises(self, fill_method, limit): | ||
# GH25006 | ||
if self._typ is DataFrame or self._typ is Series: |
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 should not be needed any longer, Panels are gone
pandas/core/generic.py
Outdated
raise ValueError("cannot pass both skipna and limit") | ||
if skipna is None and fill_method is None and limit is None: | ||
skipna = True | ||
if skipna and self._typ == 'dataframe': |
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.
Hmm maybe add this to the frame subclass instead? Somewhat confusing to introspect here in the shared one.
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 needs a subsection in the whatsnew to show the previous and current behavior.
@TomAugspurger yes, the behavior you are interested in can be achieved by setting
I totally agree with you that the behavior with |
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 think settingt he default skipna=True
is good. I believe this simplifies the checking a bit as well.
doc/source/whatsnew/v0.25.0.rst
Outdated
@@ -86,6 +86,7 @@ Other API Changes | |||
- :class:`DatetimeTZDtype` will now standardize pytz timezones to a common timezone instance (:issue:`24713`) | |||
- ``Timestamp`` and ``Timedelta`` scalars now implement the :meth:`to_numpy` method as aliases to :meth:`Timestamp.to_datetime64` and :meth:`Timedelta.to_timedelta64`, respectively. (:issue:`24653`) | |||
- :meth:`Timestamp.strptime` will now rise a ``NotImplementedError`` (:issue:`25016`) | |||
- Default `skipna=True` for :meth:`Series.pct_change` and :meth:`DataFrame.pct_change` will drop NAs before calculation (:issue:`25006`) |
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.
right, maybe also say adding the skipna
arg (as its not obvious that it was added in the note)
@albertvillanova can you merge master and address latest comments? |
can you merge master |
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.
@albertvillanova small comment; pls merge master and ping on green.
doc/source/whatsnew/v0.25.0.rst
Outdated
@@ -86,6 +86,7 @@ Other API Changes | |||
- :class:`DatetimeTZDtype` will now standardize pytz timezones to a common timezone instance (:issue:`24713`) | |||
- ``Timestamp`` and ``Timedelta`` scalars now implement the :meth:`to_numpy` method as aliases to :meth:`Timestamp.to_datetime64` and :meth:`Timedelta.to_timedelta64`, respectively. (:issue:`24653`) | |||
- :meth:`Timestamp.strptime` will now rise a ``NotImplementedError`` (:issue:`25016`) | |||
- Default `skipna=True` for :meth:`Series.pct_change` and :meth:`DataFrame.pct_change` will drop NAs before calculation (:issue:`25006`) |
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.
can you say that thiis is current behavior and the default is NO change.
I think only a small comment left, can you merge master and respond. |
can you merge master here |
Rebased to keep current. Let's see if we can get this one in |
Seems that CI is failing (haven't looked closely). Is the release note accurate (just an enhancement, not an API change?) Looks like we need a docstring example with |
Updated docstring, though on closer look this does change the default behavior against master: before change: >>> s = pd.Series([90, 91, np.nan, 85, np.nan, 95])
>>> s.pct_change()
0 NaN
1 0.011111
2 0.000000
3 -0.065934
4 0.000000
5 0.117647
dtype: float64 this branch: >>> s = pd.Series([90, 91, np.nan, 85, np.nan, 95])
>>> s.pct_change()
0 NaN
1 0.011111
2 NaN
3 -0.065934
4 NaN
5 0.117647
dtype: float64 So I think need to be careful here |
Hmm thanks for checking. This seems like something we can do in a backwards-compatible way (possibly with a deprecation). |
I've personally put this on the back burner for now - @albertvillanova are you interested in picking back up? |
I think this requires some effort to manage the backwards compat piece but not something I personally have time / motivation to dedicate to. Looks stale otherwise so closing, but @albertvillanova if something you'd like to pick back up please ping and we can continue on! |
git diff upstream/master -u -- "*.py" | flake8 --diff