-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Use ea interface to calculate accumulator functions for datetimelike #50297
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
""" | ||
try: | ||
fill_value = { | ||
np.cumprod: 1, |
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.
is np.cumprod relevant?
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.
Hm I guess we can remove it
return result | ||
|
||
|
||
def cumsum(values: np.ndarray, *, skipna: bool = 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.
-> np.ndarray
?
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.
Yep good point, this one works. The others aren't that easy...
pandas/core/arrays/datetimelike.py
Outdated
|
||
raise TypeError(f"Accumulation {name} not supported for {type(self)}") | ||
return type(self)._simple_new( | ||
result, freq=self.freq, dtype=self.dtype # type: ignore[call-arg] |
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 dont think retaining self.freq is going to be correct in general
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 elaborate when we should set freq to None?
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.
Pretty much anything that isn't a no-op should be not-freq-preserving. e.g. pd.date_range("2016-01-01", periods=3)._data.cummin()
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.
Thx, makes sense. Should we retain the freq in cases where we only have one element or not retain in general?
Not easy to hit btw :) But added a test now
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.
id just not-retain in general
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.
Sounds good, that's how I implemented it right now
("cummax", pd.Period("2012-1-2", freq="D")), | ||
], | ||
) | ||
def test_cummin_cummax_period(self, func, exp): |
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 checking this
|
||
Parameters | ||
---------- | ||
func : np.cumsum, np.cumprod, np.maximum.accumulate, np.minimum.accumulate |
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.
func : np.cumsum, np.cumprod, np.maximum.accumulate, np.minimum.accumulate | |
func : np.cumsum, np.maximum.accumulate, np.minimum.accumulate |
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.
thx removed
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.
LGTM merge when ready @phofl or @jbrockmendel
) | ||
|
||
elif skipna and not issubclass(values.dtype.type, (np.integer, np.bool_)): | ||
if skipna and not issubclass(values.dtype.type, (np.integer, np.bool_)): |
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.
maybe a comment/check that "mM" cases should not get 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.
(OK for follow-up, i can add this into my next "assorted" branch)
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 an assert
@@ -0,0 +1,46 @@ | |||
import pytest |
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 call this test_cumulative.py to match tests/series/ and tests/frame/
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
Thanks @phofl |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.cc @jbrockmendel Follow up from the other pr
As mentioned on the other pr, this changes the behavior (highlighted by the test).