-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
[WIP, ENH] Adds cumulative methods to ea #28509
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
Changes from 4 commits
2897723
a54e1b4
10abc0f
c2d7592
2c149c0
79cea11
12a5ca3
dc959f4
bcfb8a8
9a8f4ec
5d837d9
9e9f0c3
a1a1cb2
6d967ad
73363bf
0d9a3d5
84a7d81
ce6869d
3b5d1d8
0337cb0
f0722f5
99baa1b
fa35b14
43fca7c
7bd6378
185510b
2ef9ebb
7d898bd
09b42be
af0dd24
bc9a36a
38454a3
5ecfa51
8d62594
5f3b624
06d1286
7efcb5f
ae5f969
f7e3f4f
aa99927
9cab6d9
b3ae864
52e6486
99fb664
d339250
be6f974
a902f4e
64afb5b
1e5d77b
c95b490
dc669de
08475a4
67fa99a
a36632b
b3d3c81
f8f6367
ad6773d
663c301
e17f3a0
8cb66f9
4f953cf
b33a5df
18ec178
305bdc7
56bfb23
63db854
9c91c55
6ba3ca9
f2a49b3
386fa39
55de384
6a5b7f8
9c63c64
84dd141
2f23499
a5b30e6
d22c8a0
a5866c7
8255457
483b608
150fd3b
80e2dc6
dceab99
1c14f18
e20501a
53147c4
597e978
5ebe8ea
32367c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,7 @@ class ExtensionArray: | |
take | ||
unique | ||
view | ||
_accumulate | ||
_concat_same_type | ||
_formatter | ||
_from_factorized | ||
|
@@ -114,8 +115,9 @@ class ExtensionArray: | |
as they only compose abstract methods. Still, a more efficient | ||
implementation may be available, and these methods can be overridden. | ||
|
||
One can implement methods to handle array reductions. | ||
One can implement methods to handle array accumulations or reductions. | ||
|
||
* _accumulate | ||
* _reduce | ||
|
||
One can implement methods to handle parsing from strings that will be used | ||
|
@@ -407,6 +409,7 @@ def isna(self) -> ArrayLike: | |
|
||
* ``na_values._is_boolean`` should be True | ||
* `na_values` should implement :func:`ExtensionArray._reduce` | ||
* `na_values` should implement :func:`ExtensionArray._accumulate` | ||
* ``na_values.any`` and ``na_values.all`` should be implemented | ||
""" | ||
raise AbstractMethodError(self) | ||
|
@@ -992,6 +995,35 @@ def _ndarray_values(self) -> np.ndarray: | |
""" | ||
return np.array(self) | ||
|
||
def _accumulate(self, name, skipna=True, **kwargs): | ||
""" | ||
Return an array result of performing the accumulation operation. | ||
|
||
Parameters | ||
---------- | ||
name : str | ||
Name of the function, supported values are: | ||
{ cummin, cummax, cumsum, cumprod }. | ||
datajanko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
skipna : bool, default True | ||
If True, skip NaN values. | ||
datajanko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
**kwargs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be for numpy compatibility (axis, dtype, out). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are your expectations adding this? Do you purely want to have it (for this ticket) as accessor, which we'll ignore? If not, I'd guess the impact of axis is None, but dtype might be interesting. I.e for cumsum and integer dtypes, we could also provide the target output type, so not defaulting to (U)Int64. But I don't know if this should be part of this issue There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea would be for something like |
||
Additional keyword arguments passed to the accumulation function. | ||
Currently, no is the only supported kwarg. | ||
datajanko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Returns | ||
------- | ||
array | ||
|
||
Raises | ||
------ | ||
TypeError : subclass does not define accumulations | ||
""" | ||
raise TypeError( | ||
"cannot perform {name} with type {dtype}".format( | ||
datajanko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name=name, dtype=self.dtype | ||
) | ||
) | ||
|
||
def _reduce(self, name, skipna=True, **kwargs): | ||
""" | ||
Return a scalar result of performing the reduction operation. | ||
|
Uh oh!
There was an error while loading. Please reload this page.